Author Posts

April 15, 2014 at 6:30 am

Hi,

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 🙂

April 15, 2014 at 6:43 am

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

April 16, 2014 at 7:42 pm

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