Powershell Get-Service Status Property Issue in Version >= 5.1
In this article, we will explore the issue with the Status property when using the Get-Service cmdlet in Powershell version greater than or equal to 5.1, and why it may not match a parameter name despite still being valid.
Overview
The Get-Service cmdlet in Powershell is a powerful tool for managing and monitoring services on a local or remote computer. One of the most commonly used properties of the returned service object is the Status property, which indicates whether the service is currently running or not.
The Issue
However, when using the Get-Service cmdlet with the Status property as a parameter in Powershell version greater than or equal to 5.1, you may encounter an error stating that the parameter was not found.
Here is an example of the issue:
PS C:\> get-service -Status Running
Get-Service: parameter not found
Despite the error, the Status property still exists and can be accessed on the returned service object.
Reason behind the Issue
The reason behind this issue is that the -Status parameter has been deprecated in favor of the Status parameter set in Powershell version 5.1 and later. This means that the -Status parameter can no longer be used as a parameter for the Get-Service cmdlet, but the Status property can still be accessed on the returned service object.
Solution
To avoid the issue, you can simply use the Status parameter set instead of the -Status parameter.
Here is an example:
PS C:\> get-service | where-object {$_.Status -eq 'Running'}
This will return all services that are currently running.
Although the Status property of the Get-Service cmdlet can no longer be used as a parameter in Powershell version greater than or equal to 5.1, it can still be accessed on the returned service object. By using the Status parameter set instead of the -Status parameter, you can avoid the issue and correctly retrieve the desired service status information.
References
- Get-Service Cmdlet (Microsoft Docs)
- Why does Get-Service -Status not work in Windows Powershell 5.1? (Stack Overflow)