PowerShell Version 5 New Feature: NoWait Parameter added to Stop-Service
I presented a session on “What’s New in PowerShell Version 5?” at TechStravaganza in Atlanta this past Friday and there was a lot of information I wasn’t able to get to because of the massive amount of information that I’ve compiled about the updates to PowerShell version 5 that are in the May 2014 preview version so I thought I would blog about them.
He’s a picture of me presenting at TechStravaganza in Atlanta this past Friday. The event was held at the Georgia Tech Research Institute Conference Center:
They must have known I was going to speak on PowerShell as the wording at the bottom of the plaque on the podium says “Problem Solved” as shown in the previous image.
One of the new features is that Stop-Service
now has a NoWait
parameter. When you stop a service
that doesn’t immediately stop, by default a warning is received stating that in this example:
1Invoke-Command -ComputerName web01 {
2 Stop-Service -Name IISAdmin -PassThru
3}
1WARNING: Waiting for service ‘IIS Admin Service (IISAdmin)’ to stop…
2WARNING: Waiting for service ‘IIS Admin Service (IISAdmin)’ to stop…
With this new NoWait
parameter, your prompt is returned back to you immediately:
1Invoke-Command -ComputerName web01 {
2 Stop-Service -Name IISAdmin -NoWait -PassThru
3}
Notice that in the previous example, specifying the PassThru
parameter didn’t cause any results to
be returned when used with the NoWait parameter. This leads me to believe that these two parameters
will end up being in mutually exclusive parameter sets in the final release version.
To give you a better idea of what’s going on under the covers, I’ll stop the service specifying the
NoWait
parameter and then immediately get the status of the service with the Get-Service
cmdlet. I
typically wouldn’t use the Format-Table
cmdlet in this scenario, but without the AutoSize
parameter
the value of the Status
property is truncated:
1Invoke-Command -ComputerName web01 {
2 Stop-Service -Name IISAdmin -NoWait
3 Get-Service -Name IISAdmin | Format-Table -AutoSize
4}
This blog article is one of many that I've written and will be writing about the new features in PowerShell version 5. You can find my other blog articles on PowerShell version 5 here.
µ