How to redirect the output of a PowerShell 5.0 script to a file using cmd in Windows 10? I tried the following:
powershell ".\myscript.ps1 | Out-File outfile.txt"
and:
powershell .\myscript.ps1 > outfile.txt
to no avail. The outfile.txt
is created but remains empty. The command prompt window is run with Administrator privileges.
In a script I use:
Write-Host $MyVar
Write-Host $SomeOtherVar
to output the values to a screen.