如何在 PowerShell 中获取服务的所有可用属性和方法?
powershellmicrosoft technologiessoftware & coding
要显示 get-service cmdlet 的所有可用属性和方法,您需要使用管道 Get-Member(别名 gm)。成员类型"Property"用于显示特定属性,例如 machinename、servicename 等。使用成员类型"Method",您可以对对象执行特定操作,例如启动、停止、暂停服务等。
命令
以下命令用于显示 Get-Service 的所有成员(属性、方法)。
Get-Service | Get-Member
输出
Name MemberType ---- ---------- Name AliasProperty RequiredServices AliasProperty Disposed Event Close Method Continue Method CreateObjRef Method Dispose Method Equals Method ExecuteCommand Method GetHashCode Method GetLifetimeService Method GetType Method InitializeLifetimeService Method Pause Method Refresh Method Start Method Stop Method WaitForStatus Method CanPauseAndContinue Property CanShutdown Property CanStop Property Container Property DependentServices Property DisplayName Property MachineName Property ServiceHandle Property ServiceName Property ServicesDependedOn Property ServiceType Property Site Property StartType Property Status Property ToString ScriptMethod
命令
仅获取属性。
Get-Service | Get-Member | where{$_.MemberType -eq "Property"}
输出
Name MemberType ---- ---------- CanPauseAndContinue Property CanShutdown Property CanStop Property Container Property DependentServices Property DisplayName Property MachineName Property ServiceHandle Property ServiceName Property ServicesDependedOn Property ServiceType Property Site Property StartType Property Status Property
命令
仅获取方法。
输出
Get-Service | Get-Member | where{$_.MemberType -eq "Method"}
输出
Name MemberType ---- ---------- Close Method Continue Method CreateObjRef Method Dispose Method Equals Method ExecuteCommand Method GetHashCode Method GetLifetimeService Method GetType Method InitializeLifetimeService Method Pause Method Refresh Method Start Method Stop Method WaitForStatus Method

