
As a PowerShell beginner, one of the most important cmdlets you need to know is Out-File. This incredibly useful cmdlet allows you to export output from PowerShell commands and scripts into text files. Whether you need to log results, generate reports, log events, or save data for later use, PowerShell has several commands that can help you output to a file.
In this comprehensive guide, you’ll learn everything you need to start effectively using the Out-File as a PowerShell beginner. We’ll cover the basics of the cmdlet, including the different commands, syntax, formatting your output, appending vs. overwriting files, and real-world examples.
What is the Out-File Cmdlet?
The Out-File cmdlet sends output from a PowerShell command to a text file. The output is written to the specified path and file name. This can be useful for many purposes, such as generating reports, creating backups, or logging events. By default, Out-File creates a new file or overwrites an existing file with the output. It provides several parameters to customize the behavior and format of the output file. There are several commands in PowerShell that can be used to output a file, including Out-File, Add-Content, and Set-Content.
Out-File is the most basic command for outputting to a file. It saves the output of a command to a file, overwriting any existing content. Add-Content, on the other hand, appends the output to the end of an existing file. Set-Content is similar to Out-File, but it overwrites the entire file instead of just appending to it.
Understanding the Different cmdlets in PowerShell to Write to File
Before diving into the specific commands, let’s look at the differences between Out-File, Add-Content, and Set-Content.
- Out-File: This command saves the output of a command to a file. It overwrites any existing content in the file. The default file format is Unicode, but you can specify a different format using the encoding parameter.
- Add-Content: This command appends the output of a command to the end of an existing file. If the file does not exist, it will be created. The default file format is Unicode, but you can specify a different format using the encoding parameter.
- Set-Content: This command overwrites the entire content of a file with the output of a command. If the file does not exist, it will be created. The default file format is Unicode, but you can specify a different format using the encoding parameter.
Using PowerShell Out-File Cmdlet – Syntax and Examples
Out-File is the most basic command for outputting to a file. It saves the output of a command to a file, overwriting any existing content. Here’s the basic syntax:
Out-File
[-FilePath] <String>
[[-Encoding] {unknown | string | unicode | bigendianunicode | utf8 | utf7 | utf32 | ascii | default | oem}]
[-Append]
[-Confirm]
[-Force]
[-InputObject <PSObject>]
[-NoClobber]
[-NoNewline]
[-WhatIf]
[-Width <Int32>]
[<CommonParameters>]Here is the list of important parameters for the Out-File cmdlet in PowerShell:
| Parameter | Description |
|---|---|
-Append | If specified, the cmdlet will append the output to the end of the existing file instead of overwriting it. |
-Encoding | Specifies the character encoding. Values include ascii, utf8, utf7, utf32, unicode, bigendianunicode, and default. utf8NoBOM might be available in newer PowerShell versions. |
-Force | Allows the cmdlet to override restrictions that prevent the command from succeeding, apart from security settings. For example, Out-File will overwrite a file even if it has the Read-Only attribute. |
-InputObject | Specifies the input to be written to the file. It accepts an object. |
-NoClobber | Indicates that the cmdlet should not overwrite (replace) an existing file. If used alongside -Append, this parameter will be ignored. |
-NoNewline | Omits the new line character at the end of the output. This is useful if you don’t want to introduce an additional blank line. |
-FilePath | The FilePath parameter specifies the path to the output file. It can be either a relative or an absolute path. You can also use the -LiteralPath, which takes the value precisely as entered, without interpreting any characters as wildcards. |
-Width | Specifies the number of characters in each line of output. This parameter is useful when the output width should not exceed a specified number of characters. The default value of the Windows PowerShell console host is 80 characters. |
Using the Out-File cmdlet: Basic Example
command | Out-File -FilePath "C:\Path\To\File.txt"
The -FilePath parameter specifies the path and name of the file to save the output to. Here’s an example:
Get-Process | Out-File -FilePath C:\Logs\Processes.txt
This command will save the list of processes to a file called Processes.txt in the specified path.

The key things to know about the Out-File:
- It writes command output to a text file
- You specify the file path and name with the -FilePath parameter
- It creates the file if it doesn’t exist or overwrites the file if it does exist
Appending to an Existing File with PowerShell Out-File cmdlet
In addition to creating new files or overwriting existing ones, the Out-File allows you to append data to a file. This can be useful when you want to continuously update a log file or add new information to an existing file without losing the previous content.
Here’s an example of how to append to a file using Out-File:
# PowerShell Out-File -Append example Get-ChildItem C:\Users | Out-File -FilePath "C:\Logs\FilesList.txt" -Append
The -Append parameter tells Out-File to append the output to the end of the file, instead of overwriting it. This command will append the list of file folder names in the given path to the end of the file, creating it if it does not exist.
Real-World Examples
PowerShell has several advanced techniques for working with output to file, such as using variables and formatting. Here’s an example of how to use a variable with Out-File:
$processes = Get-Process $processes | Out-File C:\Path\To\File.txt
This command saves the output of Get-Process to a variable, then outputs the variable to a file using Out-File. Formatting output is another advanced technique for working with PowerShell output to the file. Here’s an example of how to format output using Format-Table:
Get-Process | Format-Table -AutoSize | Out-File -FilePath "C:\Logs\Process.txt"
This command formats the output of Get-Process as a table, and then saves it to a file using Out-File.
The Out-File provides a wide range of functionalities for file management in PowerShell. Here are a few additional examples to demonstrate its versatility:
Example 1: Creating a file with specific encoding
$Services = Get-Service $Services | Out-File -FilePath "C:\Data\output.txt" -Encoding UTF8
This command will create a new file named “output.txt” with UTF-8 encoding and save the output of the $myData variable to it.
Example 2: Redirecting error output to a file
In PowerShell, you can redirect error output or text to a file using redirection operators. Here’s how you can do it:
Get-ChildItem -Path C:\anothernonexistentfolder 2>> "C:\Logs\ErrorLog.txt"
This command will retrieve the list of processes, suppress any error messages, and redirect the error output to the “output.txt” file.
Try { Get-Process -Name NotExists -ErrorAction Stop
}
Catch { $_.Exception | Out-File -FilePath "C:\Logs\ErrorLog.txt" -Append
}Creating CSV files with Out-File PowerShell Cmdlet
Out-File is not only limited to creating text files, but it also supports the creation of CSV files. CSV (Comma-Separated Values) files are widely used for storing and exchanging tabular data. To create a CSV file using Out-File, you need to specify the file extension as “.csv” in the file path. Additionally, you can use the -Encoding parameter to specify the encoding of the CSV file. For example:
Get-Process | Select-Object -Property ProcessName, Id, CPU | ConvertTo-Csv -NoTypeInformation | Out-File -FilePath "C:\Logs\processes.csv" -Encoding utf8
In this example, we convert the $myData variable to CSV format using the ConvertTo-Csv cmdlet, and then redirect the output to a file named “data.csv” with UTF-8 encoding.
However, it’s worth noting that while the Out-File can be used this way, PowerShell provides a more direct cmdlet for this purpose called Export-Csv. The Export-Csv is a more straightforward approach to exporting objects to a CSV file in PowerShell. It eliminates the need for ConvertTo-Csv and Out-File. How to Export to CSV using Export-CSV cmdlet in PowerShell?
Overwriting Read Only Files with Force Parameter in Out-File
By default, Out-File overwrites the content of an existing file. However, there may be situations where you want to explicitly overwrite files that are marked as Read-only. The Out-File command provides the -Force parameter to achieve this.
"New content for the file" | Out-File -FilePath "C:\output.txt" -Force
In this example, the “output.txt” file will be overwritten with the output of the $myData variable, even if it already exists. Alternatively, you can clear the read-only property of the file and then update the file. Here is how:
#Clear the Read Only Property Set-ItemProperty -Path "C:\Data\readonly.txt" -Name IsReadOnly -Value $false #Update the file "New content for the file" | Out-File -Path "readonly.txt"
Redirecting output to a file in PowerShell
In addition to redirecting the output of a command to a file using Out-File, you can also directly write output to a file using the redirection operator (>). This can be useful when you want to quickly save the output of a command without explicitly using the Out-File cmdlet.
Get-Process > "C:\output.txt"
In this example, the output of the Get-Process command will be directly written to the “output.txt” file using the > operator. Similarly, to append to an existing file, file rather than overwriting, use the >> operator:
Get-Process >> "C:\output.txt"
Redirecting Only Errors:
Use the 2> operator to redirect errors. For example, if you want to redirect errors from a command to a file named “errors.txt”:
If you want to append the errors to a file instead of overwriting it, use the 2>> operator:
Get-ChildItem -Path C:\nonexistentfolder 2>> errors.txt
Redirecting All Output:
If you want to redirect all output (standard and error) to the same file, use *>:
Get-ChildItem -Path C:\nonexistentfolder *> alloutput.txt
Here is the list of other useful redirection Operators:
- 1> or >: Redirects standard output
- 2>: Redirects error output
- 3>: Redirects warning output
- 4>: Redirects verbose output
- 5>: Redirects debug output
- 6>: Redirects information output
Get-Process | Select-Object -Property Name, CPU, Memory | Out-File -FilePath "C:\Logs\output.txt"
In this example, we use the Select-Object cmdlet to only retrieve specific properties from the output of the Get-Process command. Then, we use the Out-File cmdlet to save the modified output to the “output.txt” file.
Managing file encoding with Out-File
Encoding plays a crucial role in file management, especially when dealing with different languages and special characters. Out-File provides the -Encoding parameter that allows you to specify the encoding of the output file.
The default encoding used by Out-File is ASCII, but you can specify other encoding types such as UTF-8, UTF-16, or Unicode. For example:
Get-Process | Out-File -FilePath "C:\output.txt" -Encoding UTF8
This command will save the output of the Get-Process command to a file named “output.txt” with UTF-8 encoding.
Creating a Text file if it doesn’t exist with Out-File
Sometimes, you may need to create a file only if it doesn’t already exist. Out-File provides a convenient way to achieve this using the -Force parameter.
By specifying the -Force parameter, Out-File will create a new file if it doesn’t exist. If the file already exists, the command will overwrite the existing file. This can be useful when you want to ensure the file exists before redirecting the output to it.
Get-Process | Out-File -FilePath "C:\output.txt" -Force
In this example, the “output.txt” file will be created if it doesn’t already exist, and the output of the Get-Process command will be redirected to it.
Separating columns in a CSV file using Out-File
When working with CSV files, it’s common to separate the columns with a character other than a comma. For example, let’s say you have a CSV file with tab-separated values instead of commas. You can use Out-File to create a new CSV file with tabs as the delimiter:
Get-Service | ConvertTo-Csv -NoTypeInformation -Delimiter "`t" | Out-File -FilePath "C:\data\Services.csv"
In this command, we use the “ConvertTo-Csv” cmdlet to convert the data to CSV format and specify the tab character as the delimiter using the “`t” escape sequence.
Using delimiters with Out-File
In addition to specifying delimiters for CSV files, Out-File also allows you to use delimiters for other types of files. This can be useful when you want to separate values in a text file or customize the format of the output. For example, let’s say you have a script that generates a list of numbers, and you want to separate them with a semicolon:
$numbers = 1, 2, 3, 4, 5 $numbers -join ";" | Out-File -FilePath "C:\numbers.txt"
In this example, we use the -join operator to join the elements of the $numbers array with a semicolon delimiter, and then redirect the output to a file named “numbers.txt”.
When working with CSV files, you may encounter situations where you need to remove the header (the first row) from the file. Out-File provides a simple way to achieve this using the -NoClobber parameter.
By specifying the -NoClobber parameter, Out-File will prevent overwriting an existing file. This can be useful when you want to remove the header from a CSV file without modifying the rest of the content.
$CSVData = Get-Content -Path "C:\data\Services.csv" | Select-Object -Skip 1 $CSVData | Out-File -FilePath "C:\data\ServicesV2.csv" -NoClobber
In this example, we use the Get-Content cmdlet to read the content of the “data.csv” file and skip the first row using the Select-Object cmdlet. Then, we redirect the modified content back to the same file without overwriting it, effectively removing the header.
Combining PowerShell Output to File and Console
The Tee-Object command allows you to output the result of a command to both a file and the console. Think of it as a “T-junction” for data; it takes input from one source and directs it to two destinations. Here’s the basic syntax:
command | Tee-Object -FilePath "C:\Logs\Commands.txt"
This command will save the output of the command to a file called File.txt in the specified path, as well as display it in the PowerShell console. E.g.,
Get-command -Module PnP.PowerShell | Tee-Object -FilePath "C:\Logs\Commands.txt"
When you use Tee-Object, you can send data down the pipeline to another command AND save it to a file or variable simultaneously. You can also append to a file with -Append. Microsoft’s reference on Tee-Object cmdlet
Troubleshooting Common Issues with PowerShell Output to File
While PowerShell output to a file is a powerful tool, it can sometimes encounter issues. Here are some common issues and their solutions:
- File access denied: Ensure that you have the necessary permissions to access the file and that it is not currently open in another program.
- File not found: Double-check the path and name of the file to ensure that it exists and that there are no typos.
- Encoding issues: Ensure you are using the correct encoding for your file. Unicode is the default, but you may need to specify a different encoding depending on your needs.
Conclusion and Next Steps
In this comprehensive guide, we explored everything you need to know about PowerShell Out-file for effective file management. We learned how to redirect output to a file, append data, create CSV files, manage file encoding, create files if they don’t exist, separate columns in CSV files, and use delimiters. We also learned how to remove headers, overwrite files, write output directly to a file, and pipe output to a file. You’ll be well-equipped to handle any output-to-file needs in your PowerShell scripts by mastering these techniques.
With this knowledge, you can now master PowerShell Out-File and enhance your file management capabilities.
What is out-file in PowerShell?
Out-File is a cmdlet in PowerShell that is used to send output to a file. It allows you to redirect the output of a command or script to a text file. You can specify the file path and name, and choose whether to overwrite the existing file or append the output to it.
What is the alternative to out-file in PowerShell?
Set-Content: This cmdlet can be used to write content to a file, similar to out-file. It allows you to specify the file path and the content to be written.
What is the difference between add-content and out-file?
The Add-Content cmdlet is used to append content to an existing file. By default, It adds the new content to the end of the file without overwriting any existing content. This is useful when you want to continuously add new data to a file without losing the previous data.
How do I read a file as text in PowerShell?
To read a file as text in PowerShell, you can use the Get-Content cmdlet. Here’s an example of how to do it:$content = Get-Content -Path "C:\path\to\file.txt"
How do I pipe output to a file in PowerShell?
How do I write output to a log file in PowerShell?
How do I redirect a PowerShell output to a CSV file?
How can I redirect PowerShell output to a file?
Can I append PowerShell output to an existing file?
Do you want to save the output of your commands and scripts to a file for later review, logging, or processing in PowerShell? In this tutorial, I will show you several methods to save output to file in PowerShell with examples.
Now, let us discuss various methods to save output to a file in PowerShell.
1. Using the Out-File Cmdlet
One of the simplest and most common ways to save output in PowerShell is by using the Out-File cmdlet. This cmdlet sends output to a file, and you can specify the file path and other parameters like encoding and width.
Example:
Get-Process | Out-File -FilePath C:\Bijay\processes.txtThis command gets a list of running processes and saves it to processes.txt in the C:\Bijay directory. You can use the -Append parameter to add the output to the end of an existing file without overwriting it.
Here is the complete PowerShell script:
# Save a list of services to a file
Get-Service | Out-File -FilePath C:\Bijay\services.txt -Encoding UTF8This script saves the list of services with UTF8 encoding to the services.txt file.
You can see the output in the screenshot below after executing the script using VS Code.

2. Using Redirection Operators
Another method to save output to a file in PowerShell is by using redirection operators. The > operator in PowerShell redirects output to a file, overwriting the file if it exists. The >> operator appends the output to the end of the file in PowerShell.
Example:
Get-Process > C:\Bijay\processes.txtThis command is equivalent to the Out-File example but uses the redirection operator to save the output.
Here is the complete PowerShell script.
# Save disk space information to a file
Get-PSDrive C | Select-Object Used, Free >> C:\Bijay\disk_space.txtThis PowerShell script appends the used and free space information of the C drive to the disk_space.txt file.
3. Using The Set-Content and Add-Content Cmdlets
The Set-Content cmdlet in PowerShell is similar to Out-File, but it is more efficient when writing string data. Add-Content is the counterpart for appending data to a file.
Example:
Get-EventLog -LogName System | Set-Content -Path C:\Bijay\system_log.txtThis command writes the system event log to a file.
Here is the complete script:
# Save custom object to a file
$customObject = [PSCustomObject]@{ Date = Get-Date Files = Get-ChildItem -Path C:\
}
$customObject | Add-Content -Path C:\Bijay\custom_data.txtThis script creates a custom object with the current date and a list of files in the C: root, then appends it to custom_data.txt.
4. Using Start-Transcript and Stop-Transcript
The Start-Transcript cmdlet in PowerShell starts a transcript of all interactions with the PowerShell console, including input and output, and saves it to a file. Stop-Transcript ends the transcription.
Example:
Start-Transcript -Path C:\Bijay\session_transcript.txt
# Run various commands
Stop-TranscriptThis example starts a transcript, runs various commands (not shown), and then stops the transcript, saving everything to session_transcript.txt.
Here is the full PowerShell script:
# Transcript a session with multiple commands
Start-Transcript -Path C:\Bijay\session_transcript.txt
Get-Process
Get-Service
Stop-TranscriptThis script records a session where the list of processes and services are retrieved, and the transcript is saved to session_transcript.txt.
5. Using Export-Csv and ConvertTo-Csv
You may want to save your output in CSV format when dealing with structured data in PowerShell. The Export-Csv cmdlet and ConvertTo-Csv cmdlet to save the output in a CSV file in PowerShell.
Example:
Get-Process | Export-Csv -Path C:\Bijay\processes.csvThis command exports the list of processes to a CSV file.
Here is the complete example.
# Save system information to a CSV file
Get-ComputerInfo | Select-Object OsName, OsVersion | Export-Csv -Path C:\Bijay\system_info.csv -NoTypeInformationThis script gets the OS name and version from the system and exports it to system_info.csv, excluding the type information that Export-Csv usually includes.
6. Using ConvertTo-Json and Out-File
For a modern data exchange format like JSON, you can use the ConvertTo-Json cmdlet in combination with Out-File in PowerShell.
Example:
Get-Process | ConvertTo-Json | Out-File -FilePath C:\Bijay\processes.jsonThis command converts the process list to JSON format and saves it to processes.json.
Here is the complete PowerShell script.
# Save services with their status to a JSON file
Get-Service | Select-Object Name, Status | ConvertTo-Json | Set-Content -Path C:\Bijay\services.jsonThis script selects the name and status of services, converts them to JSON, and saves the output to services.json.
Conclusion
The easiest way to save output to a file in PowerShell is by using the Out-File Cmdlet.
In this PowerShell tutorial, I have explained how to save output to a file in PowerShell using different methods with examples.
- Using the Out-File Cmdlet
- Using Redirection Operators
- Using The Set-Content and Add-Content Cmdlets
- Using Start-Transcript and Stop-Transcript
- Using Export-Csv and ConvertTo-Csv
- Using ConvertTo-Json and Out-File
You may also like:
Starting in Windows PowerShell 5.0, Write-Host writes InformationRecord objects to the information stream. This will show if you redirect the information stream to the success stream using 6>&1:
$InformationRecord = Write-Host abc -ForegroundColor Red 6>&1
$InformationRecord | Get-Member TypeName: System.Management.Automation.InformationRecord
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Computer Property string Computer {get;set;}
ManagedThreadId Property uint ManagedThreadId {get;set;}
MessageData Property System.Object MessageData {get;}
NativeThreadId Property uint NativeThreadId {get;set;}
ProcessId Property uint ProcessId {get;set;}
Source Property string Source {get;set;}
Tags Property System.Collections.Generic.List[string] Tags {get;}
TimeGenerated Property datetime TimeGenerated {get;set;}
User Property string User {get;set;}This object holds the color information in the MessageData property and doesn’t include any ANSI control codes by itself:
$InformationRecord.MessageData | Get-Member TypeName: System.Management.Automation.HostInformationMessage
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
BackgroundColor Property System.Nullable[System.ConsoleColor] BackgroundColor {get;set;}
ForegroundColor Property System.Nullable[System.ConsoleColor] ForegroundColor {get;set;}
Message Property string Message {get;set;}
NoNewLine Property System.Nullable[bool] NoNewLine {get;set;}In other words, I don’t think that there is any way to preserve the ANSI control code fromWrite-Host. See also: Is there a way to preserve ANSI control codes in PowerShell command output?
You might consider to write your own Write-Ansi proxy command based on Write-Host but there is a general disadvantage with using the Write-Host command as you can only use a single color for the whole output which requires to make use of the -NoNewLne switch and take that in consideration for any proxy command.
Alternatives
Instead of a using a limited (not redirectable) command like:
Write-Host 'This whole line is red.' -ForegroundColor RedYou might consider using the $PSStyle object:
"This is $($PSStyle.Foreground.Red)red$($PSStyle.Reset) text" # > .\out.txtOr, using MarkDown:
'Make this *blue* text' > .\out.txt
(Get-Content .\out.txt | ConvertFrom-MarkDown -AsVT100EncodedString).VT100EncodedString
Set-MarkdownOption -ItalicsForegroundColor '[91m'
('Make this *red* text' | ConvertFrom-MarkDown -AsVT100EncodedString).VT100EncodedString > .\out.txt
Get-Content .\out.txt
Here, I will show you 5 methods for writing multiple lines to a file in PowerShell. We will discuss each method individually.
Method 1: Using Out-File and the Here-String
Here is an example of how to use a here-string with Out-File to write multiple lines to a file in PowerShell.
$multiLineText = @"
This is line one
This is line two
This is line three
"@
$multiLineText | Out-File -FilePath C:\MyFolder\file.txtThe Out-File cmdlet sends output to a file. It implicitly uses PowerShell’s formatting system to write to the file.
You can see the output in the screenshot below after I executed the PowerShell script using VS code.

Method 2: Using Add-Content
If you need to append multiple lines to an existing file without overwriting the current content, you can use the Add-Content PowerShell cmdlet.
Here’s an example and the complete PowerShell script.
$lines = @"
Appending this line to the file.
Adding another line.
"@
Add-Content -Path C:\MyFolder\file.txt -Value $linesThis method is particularly useful when you need to add to a log file or update configuration files without losing existing data.
You can see the output in the screenshot below:

Method 3: Using the Redirection Operator
PowerShell also allows you to redirect output directly to a file using the redirection operator >. In PowerShell, to append content, you’d use >> operator.
Here’s an example using the PowerShell redirection operator:
@"
This is a new line for the file.
Here's another new line.
"@ > C:\MyFolder\file.txtAnd to append data:
@"
This line will be appended.
So will this one.
"@ >> C:\MyFolder\file.txtThe redirection operator is quick and easy but offers less control compared to Out-File and Add-Content in PowerShell.
Method 4: Using Set-Content
In PowerShell, you can also use the Set-Content cmdlet to write multiple lines to a file. This cmdlet is similar to Out-File, but it does not use the PowerShell formatting system and is often faster.
Here’s how you can use the PowerShell Set-Content:
$linesToWrite = @"
Line one
Line two
Line three
"@
Set-Content -Path C:\MyFolder\file.txt -Value $linesToWriteSet-Content is a good choice when performance is a concern and when you don’t need the formatting capabilities of Out-File.
Method 5: Using a Script Block with Foreach-Object
$linesArray = "Line one", "Line two", "Line three"
$linesArray | Foreach-Object { $_ | Out-File -FilePath C:\path\to\your\file.txt -Append }This method is useful when you have a collection of strings that you want to process individually or conditionally before writing to the file in PowerShell.
Conclusion
In this article, we’ve covered several methods to write multiple lines to a file in PowerShell. Whether you’re appending to an existing file, creating a new one, or writing line by line, PowerShell provides various cmdlets to write multiple lines or strings to a file.
The easiest way to write multiple lines to a file in PowerShell is by using the Out-File and the Here-String cmdlets.
You may also like:
I’m a bit stumped at how to interpret this in PS 5.1:
First, I try to create a file with Out-File and then append to it with Add-Content and Out-File -Append:
"# Script for running installers`n`n" | Out-File $InstallTools -Encoding utf8
"sleep 5" | Add-Content $InstallTools
"Start-Process -WindowStyle Hidden `"powershell.exe`" -ArgumentList `"-NoProfile -ExecutionPolicy Bypass -File `"`"$SetupScript`"`"`"" | Out-File -Append $InstallToolsOutput is a mess:
# Script for running installers
sleep 5
S t a r t - P r o c e s s - W i n d o w S t y l e H i d d e n " p o w e r s h e l l . e x e " - A r g u m e n t L i s t " - N o P r o f i l e - E x e c u t i o n P o l i c y B y p a s s - F i l e " " C : \ U s e r s \ B o s s \ I n s t a l l w i n f e t c h . p s 1 " " " The Add-Content call works fine, whereas the Out-File -Append call causes the file corruption.
The above output is when I open in notepad. If I open in VS Code, it’s worse; I see no text after the sleep 5 just a load of nulls.
Why do the first 2 lines work fine, then the third is garbled, and how should I construct things to get meaningful output?
Edit: Believe I have resolved the problem, by adding -Encoding utf8 to the Out-File -Append lines. I read somewhere that the -Append and -Encoding switches should not be used together, but it seems they must be to get consistent output.



