Hi All,
why does running get-service ‘background intelligent transfer service’ work?
We’re doing a book club in work, based on “powershell in a month of lunches” for powershell v2 (yes, i know it’s old, but none of our customers have gone to windows 2012 yet) and we’ve noticed that something we don’t think should work, works.
if we run “help get-service” we see:
SYNTAX
Get-Service [[-Name] <string[]>] [-ComputerName <string[]>] [-DependentServices] [-Exclude <string[]>] [-Include <s
tring[]>] [-RequiredServices] [<CommonParameters>]Get-Service -DisplayName <string[]> [-ComputerName <string[]>] [-DependentServices] [-Exclude <string[]>] [-Include
<string[]>] [-RequiredServices] [<CommonParameters>]
so we take that to mean that if we type “get-service <string>” then “<string>” will be taken as input for the -Name parameter, not the display name parameter. the -DisplayName parameter isn’t in square brackets, so must be typed if you are going to use a displayname value…
now, consider the BITS service:
Name : BITS
DisplayName : Background Intelligent Transfer Service
Status : Running
DependentServices : {}
ServicesDependedOn : {EventSystem, RpcSs}
CanPauseAndContinue : False
CanShutdown : True
CanStop : True
ServiceType : Win32ShareProcess
and if i run get-service BITS | gm i see:
Name MemberType Definition
—- ———- ———-
Name AliasProperty Name = ServiceName
<snip>
DisplayName Property System.String DisplayName {get;set;}
MachineName Property System.String MachineName {get;set;}
ServiceHandle Property System.Runtime.InteropServices.SafeHandle ServiceHandle {get;}
ServiceName Property System.String ServiceName {get;set;}
ServicesDependedOn Property System.ServiceProcess.ServiceController[] ServicesDependedOn {get;}
ServiceType Property System.ServiceProcess.ServiceType ServiceType {get;}
Site Property System.ComponentModel.ISite Site {get;set;}
Status Property System.ServiceProcess.ServiceControllerStatus Status {get;}
so it looks like “Name” is definitely distinct from “DisplayName”; it’s an alias for “ServiceName”.
so, my original question… why does this work?