Guide: Redirecting PowerShell Command Results Into Files

Guide: Redirecting PowerShell Command Results Into Files

Mark Lv13

Guide: Redirecting PowerShell Command Results Into Files

Key Takeaways

  • To save a PowerShell command’s output to a TXT file, type the command, press Spacebar, type the > (greater than) symbol, press Spacebar, and type the full path to the TXT file.
  • To generate a CSV file from a PowerShell command, type your command, press Spacebar, type the | (pipe) sign, press Spacebar, type “Export-CSV”, press Spacebar, enter the full path to the CSV file, press Spacebar, type “-NoTypeInformation”, and press Enter.

Do you want to save your PowerShell command’s result in a TXT (text) or CSV (comma-separated values) file on your computer? If so, it’s easy to do, and we’ll show you how on your Windows 11 or Windows 10 PC.

Send a PowerShell Command’s Output to a Text File

To write your PowerShell command’s output to a text (TXT) file, first launch a PowerShell window . Here, type whatever command you need, the output of which you want in a text file. After you’ve typed the command, press Spacebar, type the > (greater than) symbol, press Spacebar, enter the full path to the text file where you want to save the output, and press Enter.

For example, if you want to save the “systeminfo ” command’s output to a file named “SystemInfo.txt” on your desktop, your command will look something like the following:

systeminfo > C:\Users\mahes\Desktop\SystemInfo.txt

'systeminfo' command highlighted on a PowerShell window.

DEX 3 RE is Easy-To-Use DJ Mixing Software for MAC and Windows Designed for Today’s Versatile DJ.

Mix from your own library of music, iTunes or use the Pulselocker subsciprtion service for in-app access to over 44 million songs. Use with over 85 supported DJ controllers or mix with a keyboard and mouse. 

DEX 3 RE is everything you need without the clutter - the perfect 2-deck mixing software solution for mobile DJs or hard-core hobbiests. 
PCDJ DEX 3 RE (DJ Software for Win & MAC - Product Activation For 3 Machines)

As soon as you press Enter, PowerShell creates your specified file and adds your command’s result to it. When that’s done, access your specified path, and you’ll find your newly created file there.

Send a PowerShell Command’s Output to a CSV File

If you want to create a CSV file containing the output of your specified PowerShell command, use the tool’s “Export-CSV” cmdlet .

To do that, launch PowerShell. Here, enter your command (the results of which you want in a CSV file). Then, press Spacebar, enter the | (pipe) sign, press Spacebar, enter “Export-CSV”, press Spacebar, enter the full path to the CSV file you want to create, press Spacebar, type “-NoTypeInformation”, and press Enter.

For example, if you want to save the current directory’s item list in a file called “List.csv” on your desktop, you’d use a command that looks like the following. Note that the “NoTypeInformation” parameter here tells the command not to include the #TYPE information header in your CSV file.

Get-ChildItem | Export-CSV C:\Users\mahes\Desktop\List.csv -NoTypeInformation

'Get-ChildItem' cmdlet highlighted in PowerShell.

Lyric Video Creator Professional Version

When you’ve finished running the command, you’ll have a file called “List.csv” on your desktop containing the list of the items in your current directory.

Nero Burning ROM:
The ultimate burning program for all your needs!

View Your Text or CSV File’s Contents in PowerShell

You can view your newly created text or CSV file’s contents right inside PowerShell. You don’t have to leave the tool and use another app to open your files.

To do that, open a PowerShell window, type the following command, replacing “PATH” with the full path to your text or CSV file, and press Enter.

Type PATH

For example, if you want to read the contents of a file named “SystemInfo.txt” placed on your desktop, you’d use the following command:

Type C:\Users\mahes\Desktop\SystemInfo.txt

A TXT file's contents displayed in PowerShell using the 'Type' command.

Instantly, PowerShell will load your file’s contents in your open window, allowing you to read the file content.


And that’s all there is to know about saving your PowerShell command results in text or CSV files. Enjoy!

  • Title: Guide: Redirecting PowerShell Command Results Into Files
  • Author: Mark
  • Created at : 2024-08-31 06:13:19
  • Updated at : 2024-09-01 06:13:19
  • Link: https://some-guidance.techidaily.com/guide-redirecting-powershell-command-results-into-files/
  • License: This work is licensed under CC BY-NC-SA 4.0.