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

**URL:** <https://forums.powershell.org/t/script-to-run-a-few-ps-commands-store-the-output-into-a-file/2464>\
**Category:** PowerShell Help\
**Created:** [April 15, 2014, 1:00am UTC](https://forums.powershell.org/t/script-to-run-a-few-ps-commands-store-the-output-into-a-file/2464 "2014-04-15T01:00:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![razz-tanwari](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@razz-tanwari](https://forums.powershell.org/u/razz-tanwari)\
**Post date:** [April 15, 2014, 1:00am UTC](https://forums.powershell.org/t/script-to-run-a-few-ps-commands-store-the-output-into-a-file/2464/1 "2014-04-15T01:00:08Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [April 15, 2014, 1:13am UTC](https://forums.powershell.org/t/script-to-run-a-few-ps-commands-store-the-output-into-a-file/2464/2 "2014-04-15T01:13:27Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![razz-tanwari](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@razz-tanwari](https://forums.powershell.org/u/razz-tanwari)\
**Post date:** [April 16, 2014, 2:12pm UTC](https://forums.powershell.org/t/script-to-run-a-few-ps-commands-store-the-output-into-a-file/2464/3 "2014-04-16T14:12:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:52pm UTC](https://forums.powershell.org/t/script-to-run-a-few-ps-commands-store-the-output-into-a-file/2464/4 "2024-05-16T20:52:11Z")

</div>


