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

This topic contains 2 replies, has 2 voices, and was last updated by  Damel 3 years, 4 months ago.

• Author
Posts
• #14560

Damel
Participant

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 🙂

• #14563

Dave Wyatt
Moderator

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

• #14603

Damel
Participant

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

You must be logged in to reply to this topic.