Get the App
SLTechnology News&Howtos  ›  Servers  › 

PowerShell Learning Notes-- Pipeline

Shulou Source: shulou.com Published: 2022-06-02 11:21:10 09月30日 Update

Piping is an important concept for command-line management tools. PowerShell also provides plumbing functionality to connect multiple commands in a single sequence line to accomplish some of the more complex tasks.

First, output the result to CSV or XML file

As a system administrator, I often check some system status, such as the current process of the system, the operation of the service, and so on. Although we can view it through GUI's application, sometimes we can view it from the command line and output it to a CSV or XML file, and then do some analysis and comparison, which is also a skill to master.

[output to CSV]: Get-Process | Export-CSV

Use notepad to view the output file.

Comparing the results of executing the Get-Process command in console, you can see that the output to the CSV file is much more than the information displayed on the screen. Because of the limited screen capacity, PowerShell only displays the most important information on the screen.

[output to XML]: Get-Process | Export-CliXML

"CliXML" is dedicated to PowerShell.

Use notepad to view the XML file.

Use IE to view.

Second, transfer to the printer

[command]: Get-Process | Out-Printer

Output the command results directly to the default printer.

Because the test system does not have a physical printer installed, this command stores the results directly to the PDF document.

There are certain rules about whether meaningful pipes can be formed between commands, and listen to the next decomposition.

Tags: Commands outputs files systems results pipes information screens printers important situation notepad management complexity next decomposition lieutenant general between tasks functions can be passed through the Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei MariaDB Apple OPPO Reno