In PowerShell 5.0+, you would use:
"TestTest" | Out-File -encoding ascii test.txt -NoNewline
But in earlier versions you simply can’t with that cmdlet.
Try this:
[System.IO.File]::WriteAllText($FilePath,"TestTest",[System.Text.Encoding]::ASCII)
More Related Contents:
- What’s the best way to determine the location of the current PowerShell script?
- Is there a way to make a PowerShell script work by double clicking a .ps1 file?
- Save hash table in PowerShell object notation (PSON)
- Redirecting standard input\output in Windows PowerShell
- How to perform keystroke inside powershell?
- When should I use Write-Error vs. Throw? Terminating vs. non-terminating errors
- Delete files older than 15 days using PowerShell
- How do I write to standard error in PowerShell?
- Get remote registry value
- How to get an MD5 checksum in PowerShell
- Obtaining ExitCode using Start-Process and WaitForExit instead of -Wait
- Redirection of standard and error output appending to the same log file
- How to properly -filter multiple strings in a PowerShell copy script
- copy-item With Alternate Credentials
- PowerShell – Decode System.Security.SecureString to readable password
- How do I concatenate two text files in PowerShell?
- How do I include a locally defined function when using PowerShell’s Invoke-Command for remoting?
- Methods to hex edit binary files via Powershell
- Comparing array variables in PowerShell
- Copy file remotely with PowerShell
- How to speed up Powershell Get-Childitem over UNC
- Using Invoke-Command -ScriptBlock on a function with arguments
- Gracefully stopping in Powershell
- Powershell – Reboot and Continue Script
- Hashtables and key order
- Can’t install nuget package because of “Failed to initialize the PowerShell host”
- PowerShell The term is not recognized as cmdlet function script file or operable program
- Using PowerShell to remove lines from a text file if it contains a string
- What security setting is preventing Remote PowerShell 2.0 from accessing UNC paths
- List hidden sub-directories and sizes