-在 cmdlet Get-WmiObject 中列出 属性
-List property in cmdlet Get-WmiObject
我知道 -List
在 WMI 存储库命名空间中获取 WMI 类 的名称,但我不太明白它在以下上下文中的含义:
(Get-WmiObject -list Win32_ShadowCopy).Create("C:\","ClientAcessible")
注意:CIM cmdlet 已取代 WMI cmdlet,但答案的应用有点类似,除了Get-CimInstance
不支持 -List
,但有专用的 Get-CimClass
cmdlet,调用 class 方法的最简单方法是 always使用专用的 Invoke-CimMethod
cmdlet。
(Get-WmiObject -list Win32_ShadowCopy).Create("C:\","ClientAcessible")
使用-List
参数访问Win32_ShadowCopy
class,所以为了能够通过它的 .Create()
方法 实例化 它,这需要 arguments .
相比之下,许多 WMI classes 的实例 不需要 参数,因此一个简单的 Get-WmiObject <class-name>
调用通常就足够了;例如:
Get-WmiObject Win32_ComputerSystem # no arguments needed; returns instance directly
Ansgar Wiechers 指出 获取 WMI class 的一种更简单(更快)的方法是将其名称转换为类型加速器 [wmiclass]
,所以你的基于 -List
的命令相当于:
([wmiclass] Win32_ShadowCopy).Create("C:\","ClientAcessible")
也就是说,在 WMI class[=] 上 调用方法 的方法越多 PowerShell-like 92=]就是用
Invoke-WmiMethod
。同样,基于 -List
的命令的等价物是:
Invoke-WmiMethod Win32_ShadowCopy -Name Create -ArgumentList "C:\", "ClientAcessible"
至于一般目的-List
参数:
请教PowerShell自带的帮助系统,也可以online:
PS> Get-Help Get-WmiObject -Parameter List
-List [<SwitchParameter>]
Gets the names of the WMI classes in the WMI repository namespace that is specified
by the Namespace parameter.
If you specify the List parameter, but not the Namespace parameter,
Get-WmiObject uses the Root\Cimv2 namespace by default.
This cmdlet does not use the Default Namespace registry entry in the
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WBEM\Scripting registry key
to determine the default namespace.
换句话说:-List
的目的是列出(枚举)WMI classes,可选择按 class-name 模式 过滤:
如果您没有明确使用 -NameSpace
,则假定为 ROOT\Cimv2
。
第一个位置参数 - Win32_ShadowCopy
在你的例子中 - 绑定到 -ClassName
(-Class
) 参数,在这种情况下充当 过滤器.
- 因为
Win32_ShadowCopy
是一个 字面值 class 名称,只有 class 匹配,但您可以使用 通配符(见下文)。
例如,要查找名称中包含单词 shadow
的所有 WMI classes(在命名空间 ROOT\Cimv2
中),请使用:
PS> Get-WmiObject -List -Class *shadow*
NameSpace: ROOT\cimv2
Name Methods Properties
---- ------- ----------
Win32_ShadowProvider {} {Caption, CLSID, Description, ID...}
Win32_ShadowCopy {Create, Revert} {Caption, ClientAccessible, Count, Description...}
Win32_ShadowContext {} {Caption, ClientAccessible, Description, Differential...}
Win32_ShadowStorage {Create} {AllocatedSpace, DiffVolume, MaxSpace, UsedSpace...}
Win32_ShadowVolumeSupport {} {Antecedent, Dependent}
Win32_ShadowFor {} {Antecedent, Dependent}
Win32_ShadowOn {} {Antecedent, Dependent}
Win32_ShadowBy {} {Antecedent, Dependent}
Win32_ShadowDiffVolumeSupport {} {Antecedent, Dependent}
我知道 -List
在 WMI 存储库命名空间中获取 WMI 类 的名称,但我不太明白它在以下上下文中的含义:
(Get-WmiObject -list Win32_ShadowCopy).Create("C:\","ClientAcessible")
注意:CIM cmdlet 已取代 WMI cmdlet,但答案的应用有点类似,除了Get-CimInstance
不支持 -List
,但有专用的 Get-CimClass
cmdlet,调用 class 方法的最简单方法是 always使用专用的 Invoke-CimMethod
cmdlet。
(Get-WmiObject -list Win32_ShadowCopy).Create("C:\","ClientAcessible")
使用-List
参数访问Win32_ShadowCopy
class,所以为了能够通过它的 .Create()
方法 实例化 它,这需要 arguments .
相比之下,许多 WMI classes 的实例 不需要 参数,因此一个简单的 Get-WmiObject <class-name>
调用通常就足够了;例如:
Get-WmiObject Win32_ComputerSystem # no arguments needed; returns instance directly
Ansgar Wiechers 指出 获取 WMI class 的一种更简单(更快)的方法是将其名称转换为类型加速器 [wmiclass]
,所以你的基于 -List
的命令相当于:
([wmiclass] Win32_ShadowCopy).Create("C:\","ClientAcessible")
也就是说,在 WMI class[=] 上 调用方法 的方法越多 PowerShell-like 92=]就是用
Invoke-WmiMethod
。同样,基于 -List
的命令的等价物是:
Invoke-WmiMethod Win32_ShadowCopy -Name Create -ArgumentList "C:\", "ClientAcessible"
至于一般目的-List
参数:
请教PowerShell自带的帮助系统,也可以online:
PS> Get-Help Get-WmiObject -Parameter List
-List [<SwitchParameter>]
Gets the names of the WMI classes in the WMI repository namespace that is specified
by the Namespace parameter.
If you specify the List parameter, but not the Namespace parameter,
Get-WmiObject uses the Root\Cimv2 namespace by default.
This cmdlet does not use the Default Namespace registry entry in the
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WBEM\Scripting registry key
to determine the default namespace.
换句话说:-List
的目的是列出(枚举)WMI classes,可选择按 class-name 模式 过滤:
如果您没有明确使用
-NameSpace
,则假定为ROOT\Cimv2
。第一个位置参数 -
Win32_ShadowCopy
在你的例子中 - 绑定到-ClassName
(-Class
) 参数,在这种情况下充当 过滤器.- 因为
Win32_ShadowCopy
是一个 字面值 class 名称,只有 class 匹配,但您可以使用 通配符(见下文)。
- 因为
例如,要查找名称中包含单词 shadow
的所有 WMI classes(在命名空间 ROOT\Cimv2
中),请使用:
PS> Get-WmiObject -List -Class *shadow*
NameSpace: ROOT\cimv2
Name Methods Properties
---- ------- ----------
Win32_ShadowProvider {} {Caption, CLSID, Description, ID...}
Win32_ShadowCopy {Create, Revert} {Caption, ClientAccessible, Count, Description...}
Win32_ShadowContext {} {Caption, ClientAccessible, Description, Differential...}
Win32_ShadowStorage {Create} {AllocatedSpace, DiffVolume, MaxSpace, UsedSpace...}
Win32_ShadowVolumeSupport {} {Antecedent, Dependent}
Win32_ShadowFor {} {Antecedent, Dependent}
Win32_ShadowOn {} {Antecedent, Dependent}
Win32_ShadowBy {} {Antecedent, Dependent}
Win32_ShadowDiffVolumeSupport {} {Antecedent, Dependent}