So I have a script/module I want to make that will remotely stop a bunch of services simultaneously but I’ve been struggling with how to make it work. I recently (read: yesterday) learned of workflows in Powershell and thought this was the answer to my scripting-prayers-but I am still struggling with how to make it work.
The way I’m trying to go about it is to get-service from remote computer where name is like xxx-this would return anywhere from 5-20 services; I then want to make the call to stop all of those services simultaneously/in parallel.
I guess what I’m struggling with is how to use the workflow to make this happen. I’m no PS expert and the examples I’ve seen aren’t making sense to me and time is becoming more of an issue for this.
Any advice on how to make this work?
PowerShell workflows are quite challenging to work with and have lots of gotchas. It looks like PowerShell, but it’s not. And how it behaves can be different from one run to the next. Workflows are almost never worth it.
That said, the below code would work for the simple task described. But any enhancements, such as waiting, timeouts, error handling, logging, feedback, etc., could get very complicated very quickly.
workflow Stop-RemoteServices ( [string]$ComputerName, [string]$Wildcard )
$ServiceNames = Get-Service -PSComputerName $ComputerName -Name $Wildcard |
Select-Object -ExpandProperty Name
ForEach -Parallel ( $ServiceName in $ServiceNames )
Get-Service -Name $ServiceName -PSComputerName $ComputerName |
Stop-RemoteServices -ComputerName 'localhost' -Wildcard 'xxx-*'
Thanks for the help-I’ve decided to try another avenue because it was needed quick and as you said…workflows are touchy.
I’ll continue to check out workflows because it does look like a powerful tool, but I found it not to be a quick thing to pickup and run with.