PowerShell - Pipelines

PowerShell - Pipelines

Pipeline
  • A series of commands connected by pipeline operators (|)
  • Output of Preceding command becomes input of next command
  • Objects are sequentially sent across pipeline, one by one
# Without Pipeline
Get-Service "Windows Update"
Stop-Service "Windows Update"

# With Pipeline
Get-Service "Windows Update"|Start-Service

# Uses of Pipeline
Get-Service | ft name -AutoSize
Get-Service | where {$_.DisplayName -like "Windows Update"}

# Use Passthru Parameter
New-Item .\test.txt
Rename-Item .\test.txt pest.txt

Rename-Item .\pest.txt test.txt | Get-Item
Rename-Item .\test.txt pest.txt -PassThru | Get-Item

# Know the type data of Output o a Command and how it is passed down the pipeline
Get-Service | Get-Member

help stop-service -Parameter *

image-20220105104752588

posted @ 2022-01-05 10:49  晨风_Eric  阅读(36)  评论(0编辑  收藏  举报