Script to run a few PS commands, store the output into a file.


I have a series of PS commands which I want to execute.

I wish to automate the process by using a PS script which includes all the PS commands, and then outputs the result of all those commands to a text file.

Is that possible to do so via Powershell ? Or is Powershell the best way to go about doing this ?

Thanks :slight_smile:

You can use redirection operators when calling a script, very similar to how you’d accomplish the same thing at the old command prompt:

.\YourPowerShellScript.ps1 > c:\path\to\logfile.txt 2>&1

That syntax will redirect both the Output and Error streams to a file, and is compatible with PowerShell 2.0. Starting with PowerShell 3.0, you can also redirect the Warning, Verbose and Debug streams, and you can do them all in one shot with the *> operator:

.\YourPowerShellScript.ps1 *> c:\path\to\logfile.txt

Thanks for the reply. I will look into the redirection operators.