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

Welcome Forums General PowerShell Q&A 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

Participant
4 years, 7 months ago.

• Author
Posts
• #14560

Participant
Points: 0
Rank: Member

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

Member
Points: 0
Rank: Member

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

Participant
Points: 0
Rank: Member

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

The topic ‘Script to run a few PS commands, store the output into a file.’ is closed to new replies.