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 *
相信未来 - 该面对的绝不逃避,该执著的永不怨悔,该舍弃的不再留念,该珍惜的好好把握。