我应该使用什么命令来获取有关 Powershell 的全面服务信息?
What command should I use for getting comprehensive service information on Powershell?
我需要创建一个 RPC 来检索和修改服务状态,基于“登录为”字段,在服务中可见 UI。
Get-Service 命令仅向我提供状态、名称和显示名称,但我需要更多信息。我应该在 Get-Service 中使用修饰符,还是有其他方法可以解决这个问题?
log on field in Services UI
“Get-Service”默认为您提供更多服务。
许多 Cmdlet 具有格式定义,默认情况下仅显示特定属性。
您可以使用“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 :
但是有很多间接(嵌套)成员。您可以使用“Get-Member”或使用它们来发现它们(例如 $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;}
这里是扩展视图(最多 3 级;还有更多)
[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 :
---------------------------------------------------------------------------
我需要创建一个 RPC 来检索和修改服务状态,基于“登录为”字段,在服务中可见 UI。 Get-Service 命令仅向我提供状态、名称和显示名称,但我需要更多信息。我应该在 Get-Service 中使用修饰符,还是有其他方法可以解决这个问题?
log on field in Services UI
“Get-Service”默认为您提供更多服务。 许多 Cmdlet 具有格式定义,默认情况下仅显示特定属性。
您可以使用“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 :
但是有很多间接(嵌套)成员。您可以使用“Get-Member”或使用它们来发现它们(例如 $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;}
这里是扩展视图(最多 3 级;还有更多)
[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 :
---------------------------------------------------------------------------