Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Subscribe
Archives
November 8, 2022

Everything Everywhere All at Once

You’ve heard me talk about “managing at scale” in previous articles. If you can do something to one thing, you can most likely do it for hundreds or thousands of things with little change to your command. The pipeline makes this possible.

 Get-Content .\services.txt | Restart-Service -force -PassThru

Status   Name               DisplayName
------   ----               -----------
Running  winrm              Windows Remote Management (WS-Managem…
Running  vmms               Hyper-V Virtual Machine Management
Running  HgClientService    Host Guardian Client Service
Running  winmgmt            Windows Management Instrumentation
Running  bits               Background Intelligent Transfer Servi…
Running  spooler            Print Spooler
Running  wsearch            Windows Search

I can restart a list of services with one simple line of code. But based on how a cmdlet is written, we may encounter a limitation. For example, Get-WinEvent will only accept a single computer name. I can still process a bunch of computer names in a pipelined expression.

Get-Content .\company.txt -PipelineVariable pv | Foreach-Object {
 Get-WinEvent -filterhashtable @{Logname="System";Level=2} -computername $_
}
Want to read the full issue?
GitHub Bluesky LinkedIn About Jeff
Powered by Buttondown, the easiest way to start and grow your newsletter.