Service 'McpManagementService (McpManagementService)' cannot be queried due to the following error:

Hi, I am trying to write a script to get details on a specific service in PS 7,
Get-service | ?($_.displayname -match "Windows Insider Service")
I get

Service ‘McpManagementService (McpManagementService)’ cannot be queried due to the following error:

but no error is displayed.
Then I try in a traditional powershell window I get nothing.
Is there a config or dll missing in my environment?
Thanks in advance

It’s not you, PowerShell 7 seems to have a problem with that service.

Get-Service -Exclude McpManagementService | 
    Where-Object { $_.DisplayName -match 'Windows Insider Service' }

Or better:

Get-Service -DisplayName 'Windows Insider Service'
1 Like

So many thanks for your help, yes the 2 work fine. But tell me, what is this service and why it is failing with PS? I need to write a couple of scripts but dont like to put -Exclude everywhere, in my scripts, I will try to match 3 or 4 services in different places. So, is there any fix for PS7? What is strange in Ps 5, it doesnt error, it returns nothing as follows
image

Matt, I connect to my sql server and issue the following

[SQL2K12]: PS C:\Users\salam\Documents> Get-service | Where-Object($_.displayname -match "sql")
[SQL2K12]: PS C:\Users\salam\Documents> Get-service | Where-Object($_.displayname -like "*sql*")
[SQL2K12]: PS C:\Users\salam\Documents> Get-service | Where-Object($_.displayname -like "sql")

I get nothing as well and no errors. When I issue only
Get-service
I see that there are several SQL … services as you can notice so nnot match nor like works as well on the server . This iis happening PS7 and Traditional PS
image

It’s considered best practice to filter as far to the left as possible; i.e. request only what you need, rather than request everything then filter with Where-Object.

No, the problem has not been fixed. See:

You’re using parentheses (), you should be using braces {}.

1 Like

Yes correct now it is working like a charm, so many thanks again for your help