- 1 year ago
Having issue outputting the results of script to .txt file in Powershell
Comment
1 / 1
To output the results of a PowerShell script to a text file, you can use the Out-File
cmdlet. Here's an example:
powershell# Run the script and save the output to a variable
$output = .\myscript.ps1
# Output the variable to a text file
$output | Out-File -FilePath "output.txt"
In this example, we run a PowerShell script called "myscript.ps1" and save the output to the $output
variable. We then use the Out-File
cmdlet to output the contents of the variable to a text file called "output.txt".
Alternatively, you can redirect the output of the script directly to a file using the >
operator. Here's an example:
powershell# Run the script and output the results to a text file
.\myscript.ps1 > output.txt
In this example, we run the PowerShell script "myscript.ps1" and redirect the output to a text file called "output.txt".