Some drivers throw an exception when fetched with Get-Service, but still return the object anyway
See original GitHub issueSteps to reproduce
Run in elevated PowerShell prompt:
Get-Service -Name msquic
If not run in an elevated prompt, no object is returned in PS6/7, and only the exception is shown. In PS5, the object is returned and there is no exception.
Expected behavior
From PowerShell 5:
Status Name DisplayName
------ ---- -----------
Running MsQuic msquic
Actual behavior
From PowerShell 6.2 and 7:
get-service : Service 'MsQuic (MsQuic)' cannot be queried due to the following error:
At line:1 char:1
+ get-service -name msquic
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (System.ServiceProcess.ServiceController:ServiceController) [Get-Service], ServiceCommandException
+ FullyQualifiedErrorId : CouldNotGetServiceInfo,Microsoft.PowerShell.Commands.GetServiceCommand
Status Name DisplayName
------ ---- -----------
Running MsQuic MsQuic
Environment data
PowerShell 6.2:
Name Value
---- -----
PSVersion 6.2.1
PSEdition Core
GitCommitId 6.2.1
OS Microsoft Windows 10.0.18956
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PowerShell 7:
Name Value
---- -----
PSVersion 7.0.0-preview.1
PSEdition Core
GitCommitId 7.0.0-preview.1
OS Microsoft Windows 10.0.18956
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:18 (6 by maintainers)
Top Results From Across the Web
c# - ServiceProvider.GetService<Type> throw exception for ...
It seems the problem is related to running the app as dll what need to do is to publish the app as self...
Read more >c# - asp.net core - get User at Service Layer
I use ASP.NET Core 2.1 and would like to fetch User at a service level. I've seen examples when HttpContextAccessor gets injected into...
Read more >Chapter 12. Java Persistence API (JPA)
A persistence unit defines the set of all classes that are related or grouped by the application, and which must be collocated in...
Read more >Hibernate ORM 5.5.9.Final User Guide
Use Hibernate and report any bugs or issues you find. ... public BitSet stringToObject(String xml) throws Exception { return fromString( xml ); }...
Read more >Integrating Data With External Applications
one-to-one relationship exists between an object and a database table. However, in some cases, multiple objects write data to a single table.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I got the same problem, so it is still not fixed. Here an actualized description:
Step to reproduce (no difference if elevated or not):
Get-Service McpManagementService; # also for: Get-Service *;
Actual behaviour: On Powershell 5.x : OK, it shows the service properties without an error. On Powershell 7.3.2 on Win10Pro: It shows the service properties BUT it first output the line in red (with no more info): "Get-Service: Service ‘McpManagementService (McpManagementService)’ cannot be queried due to the following error: " The problem arises if this is used in a script with trapping enabled:
$ErrorActionPreference="Stop"; Get-Service McpManagementService;
then it throws and ends the script.Reason: Usually for all services a description is provided but for this specific service the description property is is not correctly stored. For example if
service.msc
is called then the entry McpManagementService is shown with the description “<Failed to read description, Error Code: 15100>”. The reason is that the registry key items:contains probably a reference to a string in a dll which not exists. As a workaround1 the two registry key items can be corrected to the string “Universal Print Management Service”, but in my opinion the owner of the service and the dll (microsoft) should provide here fix for this. Workaround2: Use
$ErrorActionPreference="Stop"; Get-Service -ErrorAction SilentlyContinue McpManagementService;
Ignoring error is not best practice and should regular not be nessessary.Expected behaviour: It should NOT THROW, it should just display “<Failed to read description, Error Code: 15100>” or a similar error-message for the description as
service.msc
or PS 5 does. The concept of Get-Service should be to provide the service properties and not to guarantee that each creator of a service is providing a proper description!At least the error message needs to be updated.