Создание функции в windows power shell и сохранение ее как модуля

Quick Links

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.

systeminfo > C:\Users\mahes\Desktop\SystemInfo.txt
Создание функции в windows power shell и сохранение ее как модуля

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.

Get-ChildItem | Export-CSV C:\Users\mahes\Desktop\List.csv -NoTypeInformation
Создание функции в windows power shell и сохранение ее как модуля

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.

:/>  Appdata - что это за папка, для чего она нужна

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.

Type PATH
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!