Invoke-WmiMethod
调用 WMI 方法。
语法
Invoke-WmiMethod
[-Class] <String>
[-Name] <String>
[-ArgumentList <Object[]>]
[-AsJob]
[-Impersonation <ImpersonationLevel>]
[-Authentication <AuthenticationLevel>]
[-Locale <String>]
[-EnableAllPrivileges]
[-Authority <String>]
[-Credential <PSCredential>]
[-ThrottleLimit <Int32>]
[-ComputerName <String[]>]
[-Namespace <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Invoke-WmiMethod
-InputObject <ManagementObject>
[-Name] <String>
[-ArgumentList <Object[]>]
[-AsJob]
[-ThrottleLimit <Int32>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Invoke-WmiMethod
-Path <String>
[-Name] <String>
[-ArgumentList <Object[]>]
[-AsJob]
[-Impersonation <ImpersonationLevel>]
[-Authentication <AuthenticationLevel>]
[-Locale <String>]
[-EnableAllPrivileges]
[-Authority <String>]
[-Credential <PSCredential>]
[-ThrottleLimit <Int32>]
[-ComputerName <String[]>]
[-Namespace <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Invoke-WmiMethod
[-Name] <String>
[-AsJob]
[-Impersonation <ImpersonationLevel>]
[-Authentication <AuthenticationLevel>]
[-Locale <String>]
[-EnableAllPrivileges]
[-Authority <String>]
[-Credential <PSCredential>]
[-ThrottleLimit <Int32>]
[-ComputerName <String[]>]
[-Namespace <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Invoke-WmiMethod
[-Name] <String>
[-AsJob]
[-Impersonation <ImpersonationLevel>]
[-Authentication <AuthenticationLevel>]
[-Locale <String>]
[-EnableAllPrivileges]
[-Authority <String>]
[-Credential <PSCredential>]
[-ThrottleLimit <Int32>]
[-ComputerName <String[]>]
[-Namespace <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Invoke-WmiMethod
[-Name] <String>
[-AsJob]
[-Impersonation <ImpersonationLevel>]
[-Authentication <AuthenticationLevel>]
[-Locale <String>]
[-EnableAllPrivileges]
[-Authority <String>]
[-Credential <PSCredential>]
[-ThrottleLimit <Int32>]
[-ComputerName <String[]>]
[-Namespace <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
说明
Invoke-WmiMethod
cmdlet 调用 Windows Management Instrumentation (WMI) 对象的方法。
Windows PowerShell 3.0 中引入的新通用信息模型 (CIM) cmdlet 执行与 WMI cmdlet 相同的任务。 CIM cmdlet 符合 WS-Management (WSMan) 标准和 CIM 标准,该标准使 cmdlet 能够使用相同的技术来管理 Windows 计算机和运行其他作系统的计算机。 请考虑使用 Invoke-CimMethod,而不是使用 Invoke-WmiMethod
。
示例
示例 1:列出 WMI 方法参数的必需顺序
此命令列出对象的所需顺序。
Get-WmiObject Win32_Volume |
Get-Member -MemberType Method -Name Format |
Select-Object -ExpandProperty Definition
System.Management.ManagementBaseObject Format(System.String FileSystem, System.Boolean QuickFormat,
System.UInt32 ClusterSize, System.String Label, System.Boolean EnableCompression,
System.UInt32 Version)
若要在 PowerShell 3.0 中调用 WMI,不同于备用方法,并且要求以特定顺序输入对象值。
示例 2:启动应用程序的实例
([Wmiclass]'Win32_Process').Create.OverloadDefinitions
System.Management.ManagementBaseObject Create(System.String CommandLine, System.String CurrentDirectory,
System.Management.ManagementObject#Win32_ProcessStartup ProcessStartupInformation)
Invoke-WmiMethod -Path Win32_Process -Name Create -ArgumentList C:\Windows\system32\notepad.exe
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ProcessId : 11312
ReturnValue : 0
PSComputerName :
此命令通过调用 Win32_Process 类的 Create
方法来启动记事本实例。
ReturnValue 属性填充 0
,如果命令完成,则 ProcessId 属性将填充整数(下一个进程 ID 号)。
示例 3:重命名文件
$invokeWmiMethodSplat = @{
Path = "CIM_DataFile.Name='C:\scripts\test.txt'"
Name = 'Rename'
ArgumentList = 'C:\scripts\test_bu.txt'
}
Invoke-WmiMethod @invokeWmiMethodSplat
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ReturnValue : 0
此命令重命名文件。 它使用 Path 参数引用 CIM_DataFile 类的实例。 然后,它将 Rename 方法应用于该特定实例。
如果命令完成,则 ReturnValue 属性将填充 0
。
示例 4:使用“-ArgumentList”传递值数组
使用对象数组的示例 $binSD
后跟 $null
值。
$acl = Get-Acl test.txt
$binSD = $acl.GetSecurityDescriptorBinaryForm()
$invokeWmiMethodSplat = @{
Class = 'Win32_SecurityDescriptorHelper'
Name = 'BinarySDToSDDL'
ArgumentList = $binSD, $null
}
Invoke-WmiMethod @invokeWmiMethodSplat
参数
-ArgumentList
指定要传递给所调用方法的参数。 此参数的值必须是对象的数组,并且它们必须按调用方法所需的顺序显示。
Invoke-CimCommand
cmdlet 没有这些限制。
若要确定列出这些对象的顺序,请在 WMI 类上运行 GetMethodParameters()
方法,如示例 1 中所示,在本主题末尾附近。
重要
如果第一个值是包含多个元素的数组,则需要第二个值 $null
。 否则,该命令将生成错误,例如 Unable to cast object of type 'System.Byte' to type 'System.Array'.
。 请参阅上面的示例 4。
类型: | Object[] |
别名: | Args |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-AsJob
指示此 cmdlet 以后台作业的形式运行命令。 使用此参数可以运行需要很长时间才能完成的命令。
使用 AsJob 参数时,该命令返回表示后台作业的对象,然后显示命令提示符。 作业完成后,可以继续在会话中工作。 如果对远程计算机使用 Invoke-WmiMethod
,则会在本地计算机上创建作业,并且远程计算机的结果会自动返回到本地计算机。 若要管理作业,请使用包含 Job
名词(作业 cmdlet)的 cmdlet。 若要获取作业结果,请使用 Receive-Job
cmdlet。
若要将此参数用于远程计算机,必须配置本地计算机和远程计算机进行远程处理。 此外,必须使用 Windows Vista 和更高版本的 Windows 中的 以管理员身份运行 选项来启动 Windows PowerShell。 有关详细信息,请参阅 about_Remote_Requirements。
有关 Windows PowerShell 后台作业的详细信息,请参阅 about_Jobs 和 about_Remote_Jobs。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Authentication
指定要与 WMI 连接一起使用的身份验证级别。 此参数的可接受值为:
-
-1
:未更改 -
0
:默认 -
1
:无(未执行身份验证)。 -
2
:Connect(仅当客户端与应用程序建立关系时才执行身份验证)。 -
3
:呼叫(仅当应用程序收到请求时,才在每个调用开始时执行身份验证)。 -
4
:数据包(对从客户端接收的所有数据执行身份验证)。 -
5
:PacketIntegrity(对客户端和应用程序之间传输的所有数据进行身份验证和验证)。 -
6
:PacketPrivacy(使用了其他身份验证级别的属性,并且所有数据均已加密)。
类型: | AuthenticationLevel |
接受的值: | Default, None, Connect, Call, Packet, PacketIntegrity, PacketPrivacy, Unchanged |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Authority
指定用于对 WMI 连接进行身份验证的颁发机构。 可以指定标准 Windows NT LAN 管理器(NTLM)或 Kerberos 身份验证。 若要使用 NTLM,请将颁发机构设置设置为 ntlmdomain:<DomainName>
,其中 <DomainName>
标识有效的 NTLM 域名。 若要使用 Kerberos,请指定 kerberos:<DomainName>\<ServerName>
。 连接到本地计算机时,不能包含颁发机构设置。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Class
指定包含要调用的静态方法的 WMI 类。
类型: | String |
Position: | 0 |
默认值: | None |
必需: | True |
接受管道输入: | False |
接受通配符: | False |
-ComputerName
指定此 cmdlet 运行命令的计算机作为字符串数组。 默认值为本地计算机。
键入 NetBIOS 名称、IP 地址或一个或多个计算机的完全限定域名。 若要指定本地计算机,请键入计算机名称、点(.
)或 localhost
。
此参数不依赖于 Windows PowerShell 远程处理。 即使计算机未配置为运行远程命令,也可以使用 ComputerName 参数。
类型: | String[] |
别名: | Cn |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Confirm
在运行 cmdlet 之前,提示你进行确认。
类型: | SwitchParameter |
别名: | cf |
Position: | Named |
默认值: | False |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Credential
指定有权执行此作的用户帐户。 默认值为当前用户。 键入用户名,例如 User01
、Domain01\User01
或 User@Contoso.com
。 或者,输入 PSCredential 对象,例如 Get-Credential
cmdlet 返回的对象。 键入用户名时,系统会提示输入密码。
类型: | PSCredential |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-EnableAllPrivileges
指示此 cmdlet 在发出 WMI 调用之前启用当前用户的所有特权。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Impersonation
指定要使用的模拟级别。 此参数的可接受值为:
-
0
:默认(读取默认模拟级别的本地注册表,通常设置为3
:模拟。) -
1
:匿名(隐藏调用者的凭据)。 -
2
:标识(允许对象查询调用者的凭据)。 -
3
:模拟(允许对象使用调用者的凭据)。 -
4
:委托(允许对象允许其他对象使用调用方凭据)。
类型: | ImpersonationLevel |
接受的值: | Default, Anonymous, Identify, Impersonate, Delegate |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-InputObject
指定要用作输入的 ManagementObject 对象。 使用此参数时,除 Flag 和 Argument 参数以外的所有其他参数将被忽略。
类型: | ManagementObject |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-Locale
指定 WMI 对象的首选区域设置。 按首选顺序将 Locale 参数的值指定为采用 MS_<LCID>
格式的数组。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Name
指定要调用的方法的名称。 此参数是必需的,不能为 null 或为空。
类型: | String |
Position: | 1 |
默认值: | None |
必需: | True |
接受管道输入: | False |
接受通配符: | False |
-Namespace
与 类 参数一起使用时,此参数指定引用的 WMI 类或对象所在的 WMI 存储库命名空间。
类型: | String |
别名: | NS |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Path
指定 WMI 类的 WMI 对象路径,或指定 WMI 类实例的 WMI 对象路径。 指定的类或实例必须包含 Name 参数中指定的方法。
类型: | String |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | False |
接受通配符: | False |
-ThrottleLimit
为可以同时执行的 WMI作数指定限制值。 此参数与 AsJob 参数一起使用。 限制限制仅适用于当前命令,不适用于会话或计算机。
类型: | Int32 |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-WhatIf
显示 cmdlet 运行时会发生什么情况。 cmdlet 未运行。
类型: | SwitchParameter |
别名: | wi |
Position: | Named |
默认值: | False |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
输入
None
此 cmdlet 不接受任何输入。
输出
None
此 cmdlet 不生成任何输出。
备注
Windows PowerShell 包含以下 Invoke-WmiMethod
别名:
iwmi