I need to make a RPC to retrieve and modify service statuses, on the basis of the "Log on as" field, as visible in the services UI. The Get-Service command only provides me with the Status, Name, and DisplayName, but I need more information. Should I use a modifier with Get-Service, or is there another way of approaching the problem?
"Get-Service" provides you much more as you see by default. Many Cmdlets have formatting definitions and show only particular properties by default.
You can see more on the top level (=direct members) by using "Format-List * -Force"
PS> Get-Service -Name 'BITS' | fl * -Force
UserName : LocalSystem
Description : Transfers files in the background using idle network bandwidth. If the service is disabled, then any applications that depend on BITS, such as Windows Update or MSN
Explorer, will be unable to automatically download programs and other information.
DelayedAutoStart : True
BinaryPathName : C:\WINDOWS\System32\svchost.exe -k netsvcs -p
StartupType : Manual
Name : BITS
RequiredServices : {RpcSs}
CanPauseAndContinue : False
CanShutdown : False
CanStop : False
DisplayName : Background Intelligent Transfer Service
DependentServices : {}
MachineName : .
ServiceName : BITS
ServicesDependedOn : {RpcSs}
StartType : Manual
ServiceHandle :
Status : Stopped
ServiceType : Win32ShareProcess
Site :
Container :
But there are a lot of indirect (nested) members. You can discover them by using "Get-Member" or by using them them (e.g. $service.RequiredServices
).
PS> $service | Get-Member -MemberType Property
TypeName: System.Service.ServiceController#StartupType
Name MemberType Definition
---- ---------- ----------
BinaryPathName Property System.String {get;set;}
CanPauseAndContinue Property bool CanPauseAndContinue {get;}
CanShutdown Property bool CanShutdown {get;}
CanStop Property bool CanStop {get;}
Container Property System.ComponentModel.IContainer Container {get;}
DelayedAutoStart Property System.Boolean {get;set;}
DependentServices Property System.ServiceProcess.ServiceController[] DependentServices {get;}
Description Property System.String {get;set;}
DisplayName Property string DisplayName {get;set;}
MachineName Property string MachineName {get;set;}
ServiceHandle Property System.Runtime.InteropServices.SafeHandle ServiceHandle {get;}
ServiceName Property 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;}
StartType Property System.ServiceProcess.ServiceStartMode StartType {get;}
StartupType Property Microsoft.PowerShell.Commands.ServiceStartupType {get;set;}
Status Property System.ServiceProcess.ServiceControllerStatus Status {get;}
UserName Property System.String {get;set;}
Here an extended view (up to 3rd level; there are much more)
[ServiceController] BITS
> UserName : LocalSystem
> Description : Transfers files in the background using idle network bandwidth. If the service is disabled, then any applications that depend on BITS, such as Windows Update or MSN Explorer, will be unable to automatically download programs and other information.
> DelayedAutoStart : True
> BinaryPathName : C:\WINDOWS\System32\svchost.exe -k netsvcs -p
> StartupType : [ServiceStartupType] Manual
> > value__ : 3
> Name : BITS
> RequiredServices : @[ServiceController[]]
> > [0] <RequiredServices> : [ServiceController] RpcSs
> > > Name : RpcSs
> > > RequiredServices : @{[ServiceController[]]} ~[0..2] RpcEptMapper , DcomLaunch
> > > CanPauseAndContinue : False
> > > CanShutdown : False
> > > CanStop : False
> > > DisplayName : Remote Procedure Call (RPC)
> > > DependentServices :
> > > MachineName : .
> > > ServiceName : RpcSs
> > > ServicesDependedOn : @{[ServiceController[]]} ~[0..2] RpcEptMapper , DcomLaunch
> > > StartType : {[ServiceStartMode]} Automatic
> > > ServiceHandle :
> > > Status : {[ServiceControllerStatus]} Running
> > > ServiceType : {[ServiceType]} Win32ShareProcess
> > > Site :
> > > Container :
> CanPauseAndContinue : False
> CanShutdown : False
> CanStop : False
> DisplayName : Background Intelligent Transfer Service
> DependentServices : @[ServiceController[]]
> MachineName : .
> ServiceName : BITS
> ServicesDependedOn : @[ServiceController[]]
> > [0] <ServicesDependedOn> : [ServiceController] RpcSs
> > > Name : RpcSs
> > > RequiredServices : @{[ServiceController[]]} ~[0..2] RpcEptMapper , DcomLaunch
> > > CanPauseAndContinue : False
> > > CanShutdown : False
> > > CanStop : False
> > > DisplayName : Remote Procedure Call (RPC)
> > > DependentServices :
> > > MachineName : .
> > > ServiceName : RpcSs
> > > ServicesDependedOn : @{[ServiceController[]]} ~[0..2] RpcEptMapper , DcomLaunch
> > > StartType : {[ServiceStartMode]} Automatic
> > > ServiceHandle :
> > > Status : {[ServiceControllerStatus]} Running
> > > ServiceType : {[ServiceType]} Win32ShareProcess
> > > Site :
> > > Container :
> StartType : [ServiceStartMode] Manual
> > value__ : 3
> ServiceHandle :
> Status : [ServiceControllerStatus] Stopped
> > value__ : 1
> ServiceType : [ServiceType] Win32ShareProcess
> > value__ : 32
> Site :
> Container :
---------------------------------------------------------------------------