Skip to content

Improve error message for Get-Service with an invalid ComputerName #2747

@joeyaiello

Description

@joeyaiello

Filed on UserVoice: http://windowsserver.uservoice.com/forums/301869/suggestions/17193962

The error message for Get-Service returns a NoServiceFoundForGivenName exception even when the problem is an invalid -ComputerName, potentially misleading the user.

Steps to reproduce

Get-Service wuauserv -ComputerName MadeUpComputerName

Expected behavior

Get-Service : Cannot find any computer with name 'MadeUpComputerName'.
At line:1 char:1
+ Get-Service wuauserv -ComputerName MadeUpComputerName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (wuauserv:String) [Get-Service], ServiceCommandExce
   ption
    + FullyQualifiedErrorId : SomeOtherExceptionForComputerNameNotFound,Microsoft.PowerShell.Commands.GetService
   Command

Actual behavior

Get-Service : Cannot find any service with service name 'wuauserv'.
At line:1 char:1
+ Get-Service wuauserv -ComputerName MadeUpComputerName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (wuauserv:String) [Get-Service], ServiceCommandExce
   ption
    + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetService
   Command

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSRemotingProtocolVersion      2.3
PSVersion                      6.0.0-alpha
WSManStackVersion              3.0
BuildVersion                   3.0.0.0
SerializationVersion           1.1.0.1
PSEdition                      Core
GitCommitId                    v6.0.0-alpha.12
CLRVersion
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-FixedThe issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions