简体   繁体   English

CIM,Win32_OperatingSystem和Win32ShutdownTracker

[英]CIM, Win32_OperatingSystem, and Win32ShutdownTracker

I'm trying to convert some PowerShell code from using WMI to using CIM. 我正在尝试将某些PowerShell代码从使用WMI转换为使用CIM。 I had a function which used Win32ShutdownTracker ( https://msdn.microsoft.com/en-us/windows/desktop/aa394057 ) to reboot a system, with a timeout, comment, and reason for initiating the reboot. 我有一个使用Win32ShutdownTracker( https://msdn.microsoft.com/zh-cn/windows/desktop/aa394057 )来重新启动系统的函数,其中包含超时,注释以及启动重新启动的原因。 Using WMI I had to give the account running the reboot permissions using “psbase.Scope.Options.EnablePrivileges = $true” even though the account was already an administrator on the local system. 使用WMI,即使该帐户已经是本地系统的管理员,我也必须使用“ psbase.Scope.Options.EnablePrivileges = $ true”授予运行该帐户的重启权限。 I have not figured out how to give the same permissions using CIM and it seems without them, I'm unable to reboot the system. 我还没有弄清楚如何使用CIM授予相同的权限,而且如果没有它们,我将无法重新启动系统。 Also, the class binding does not seem to work. 另外,类绑定似乎不起作用。 Any help would be greatly appreciated. 任何帮助将不胜感激。

I've tried many combinations of CIM, including getting the object then invoking it and calling the class directly and none have worked. 我尝试了CIM的许多组合,包括获取对象然后调用它并直接调用该类,但没有一个起作用。

WMI Code (Works without issue): WMI代码(可以正常运行):

$OSObject  = Get-WmiObject -Class Win32_OperatingSystem
$OSObject.psbase.Scope.Options.EnablePrivileges = $true
$OSObject.Win32ShutdownTracker(300,"This is a test",2147745794,6) 

CIM Code I've tried (Does not work): 我尝试过的CIM代码(无效):

$OSObject  = Get-CimInstance -Class Win32_OperatingSystem
$OSObject.psbase.Scope.Options.EnablePrivileges = $true

The property 'EnablePrivileges' cannot be found on this object. 在此对象上找不到属性“ EnablePrivileges”。 Verify that the property exists and can be set. 验证该属性存在并且可以设置。 At line:1 char:1 + $OSObject.psbase.Scope.Options.EnablePrivileges = $true + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound 在第1行:char:1 + $ OSObject.psbase.Scope.Options.EnablePrivileges = $ true + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:PropertyNotFound

Invoke-CimMethod -CimClass $OSObject -MethodName Win32ShutdownTracker –Arguments 300,"This is a test",21477
45794,6

Invoke-CimMethod : Cannot bind parameter 'CimClass'. Invoke-CimMethod:无法绑定参数“ CimClass”。 Cannot convert the "Win32_OperatingSystem: Microsoft Windows 10 Enterprise" value of type "Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_OperatingSystem" to type "Microsoft.Management.Infrastructure.CimClass". 无法将类型“ Microsoft.Management.Infrastructure.CimInstance#root / cimv2 / Win32_OperatingSystem”的“ Win32_OperatingSystem:Microsoft Windows 10 Enterprise”值转换为类型“ Microsoft.Management.Infrastructure.CimClass”。 At line:1 char:28 + Invoke-CimMethod -CimClass $OSObject -MethodName Win32ShutdownTracker ... + ~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-CimMethod], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Management.Infrastructure.CimCmdlets.Invok eCimMethodCommand 第1行:28位字符+ Invoke-CimMethod -CimClass $ OSObject -MethodName Win32ShutdownTracker ... + ~~~~~~~~ + + CategoryInfo:InvalidArgument:(:) [Invoke-CimMethod],ParameterBindingException + FullyQualifiedErrorId:CannotConvertArgumentNoMessage ,Microsoft.Management.Infrastructure.CimCmdlets.Invok eCimMethodCommand

Invoke-CimMethod -CimClass "Win32_OperatingSystem" -MethodName Win32ShutdownTracker –Arguments @{300,"This is a test",2147745794,6}

Invoke-CimMethod -CimClass "Win32_OperatingSystem" -MethodName Win32ShutdownTracker –Arguments @{300,"This
is a test",2147745794,6}
Invoke-CimMethod -CimClass "Win32_OperatingSystem" -MethodName "Win32ShutdownTracker" –Arguments 300,"This
is a test",2147745794,6

Invoke-CimMethod : Cannot bind parameter 'CimClass'. Invoke-CimMethod:无法绑定参数“ CimClass”。 Cannot convert the "Win32_OperatingSystem" value of type "System.String" to type "Microsoft.Management.Infrastructure.CimClass". 无法将类型“ System.String”的“ Win32_OperatingSystem”值转换为类型“ Microsoft.Management.Infrastructure.CimClass”。 At line:1 char:28 + Invoke-CimMethod -CimClass "Win32_OperatingSystem" -MethodName "Win32 ... + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-CimMethod], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Management.Infrastructure.CimCmdlets.Invok eCimMethodCommand 第1行:28位字符+ Invoke-CimMethod -CimClass“ Win32_OperatingSystem” -MethodName“ Win32 ... + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: InvalidArgument:(:) [Invoke-CimMethod],ParameterBindingException + FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.Management.Infrastructure.CimCmdlets.Invok eCimMethodCommand

Invoke-CimMethod -CimClass "Win32_OperatingSystem" -MethodName Win32ShutdownTracker –Arguments 300,"This is
 a test",2147745794,6

Invoke-CimMethod : Cannot bind parameter 'CimClass'. Invoke-CimMethod:无法绑定参数“ CimClass”。 Cannot convert the "Win32_OperatingSystem" value of type "System.String" to type "Microsoft.Management.Infrastructure.CimClass". 无法将类型“ System.String”的“ Win32_OperatingSystem”值转换为类型“ Microsoft.Management.Infrastructure.CimClass”。 At line:1 char:28 + Invoke-CimMethod -CimClass "Win32_OperatingSystem" -MethodName Win32S ... + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-CimMethod], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Management.Infrastructure.CimCmdlets.Invok eCimMethodCommand 第1行:28位字符+ Invoke-CimMethod -CimClass“ Win32_OperatingSystem” -MethodName Win32S ... + ~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo:InvalidArgument :(:) [Invoke-CimMethod],ParameterBindingException + FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.Management.Infrastructure.CimCmdlets.Invok eCimMethodCommand

(Invoke-CimMethod -CimClass 'Win32_OperatingSystem').Win32ShutdownTracker(300,"This is a test",2147745794,6
)

Invoke-CimMethod : Cannot bind parameter 'CimClass'. Invoke-CimMethod:无法绑定参数“ CimClass”。 Cannot convert the "Win32_OperatingSystem" value of type "System.String" to type "Microsoft.Management.Infrastructure.CimClass". 无法将类型“ System.String”的“ Win32_OperatingSystem”值转换为类型“ Microsoft.Management.Infrastructure.CimClass”。 At line:1 char:29 + (Invoke-CimMethod -CimClass 'Win32_OperatingSystem').Win32ShutdownTra ... + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-CimMethod], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Management.Infrastructure.CimCmdlets.Invok eCimMethodCommand 在第1行:char:29 +(Invoke-CimMethod -CimClass'Win32_OperatingSystem')。Win32ShutdownTra ... + ~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo: InvalidArgument:(:) [Invoke-CimMethod],ParameterBindingException + FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.Management.Infrastructure.CimCmdlets.Invok eCimMethodCommand

(Invoke-CimMethod -CimClass $OSObject).Win32ShutdownTracker(300,"This is a test",2147745794,6)

Invoke-CimMethod : Cannot bind parameter 'CimClass'. Invoke-CimMethod:无法绑定参数“ CimClass”。 Cannot convert the "Win32_OperatingSystem: Microsoft Windows 10 Enterprise" value of type "Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_OperatingSystem" to type "Microsoft.Management.Infrastructure.CimClass". 无法将类型“ Microsoft.Management.Infrastructure.CimInstance#root / cimv2 / Win32_OperatingSystem”的“ Win32_OperatingSystem:Microsoft Windows 10 Enterprise”值转换为类型“ Microsoft.Management.Infrastructure.CimClass”。 At line:1 char:29 + (Invoke-CimMethod -CimClass $OSObject).Win32ShutdownTracker(300,"This ... + ~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-CimMethod], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Management.Infrastructure.CimCmdlets.Invok eCimMethodCommand 在第1行:char:29 +(Invoke-CimMethod -CimClass $ OSObject).Win32ShutdownTracker(300,“ This ... + ~~~~~~~~~ + CategoryInfo:InvalidArgument:(:) [Invoke-CimMethod] ,ParameterBindingException + FullyQualifiedErrorId:CannotConvertArgumentNoMessage,Microsoft.Management.Infrastructure.CimCmdlets.Invok eCimMethodCommand

This works for me: 这对我有用:

$arguments = @{
    Timeout    = [System.UInt32]300
    Comment    = 'This is a test'
    ReasonCode = [System.UInt32]2147745794
    Flags      = 6
}

Invoke-CimMethod -Query 'SELECT * FROM Win32_OperatingSystem' -MethodName 'Win32ShutdownTracker' –Arguments $arguments

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Powershell GWMI win32_operatingsystem 修剪输出 - Powershell GWMI win32_operatingsystem trim output 将Win32_OperatingSystem的CountryCode转换为国家/地区字符串 - Convert CountryCode of Win32_OperatingSystem to the country string Get-CimInstance -ClassName Win32_bios, Win32_operatingsystem,? - Get-CimInstance -ClassName Win32_bios, Win32_operatingsystem,? 正则表达式从字符串(gwmi Win32_OperatingSystem).Name中提取数字 - Regex to extract number from string (gwmi Win32_OperatingSystem).Name PowerShell-Win32_OperatingSystem中的Select-Object显示异常 - PowerShell - Select-Object from Win32_OperatingSystem displays rather oddly cordova 安装错误 - 命令失败:powershell (Get-CimInstance -ClassName Win32_OperatingSystem).caption 术语“Get-CimInstance”不是重新 - cordova installation error -Command failed: powershell (Get-CimInstance -ClassName Win32_OperatingSystem).caption The term 'Get-CimInstance' is not re Powershell Win32_OperatingSystem选择标题与操作系统版本“ Microsoft Windows Server 2008 R2 Enterprise”进行比较导致错误的结果 - Powershell Win32_OperatingSystem select Caption compare with OS Version 'Microsoft Windows Server 2008 R2 Enterprise' resulting wrong result 没有捕获WIN32 cim异常 - Not catching WIN32 cim exception CIM_USBDevice,CIM_USBHub和Win32_USBHub有什么区别? - What is the difference between CIM_USBDevice, CIM_USBHub, and Win32_USBHub? Cim_PhysicalMemory和Win32_ComputerSystem返回不同的内存量 - Cim_PhysicalMemory and Win32_ComputerSystem return different amount of memory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM