使用Invoke-CimMethod“激活”来激活Windows Powerplan,相反,我得到了无效类,我在做什么错?

时间:2018-08-22 15:24:02

标签: powershell invoke cim

我遵循了Microsoft脚本专家的指示,但即使如此,我仍然遇到相同的错误Scripting Guy article

这是我的脚本:
$p2=Get-CimInstance -N root\cimv2\power -Class win32_PowerPlan -Filter "ElementName = 'Balanced'" Invoke-CimMethod -InputObject $p2-MethodName Activate

其结果是:
Invoke-CimMethod : This method is not implemented in any class At line:1 char:1 + Invoke-CimMethod -InputObject $p2 -MethodName Activate + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : MetadataError: (Win32_PowerPlan...2-f694-41f0...):CimInstance) [Invoke-CimMethod], CimException + FullyQualifiedErrorId : HRESULT 0x80041055,Microsoft.Management.Infrastructure.CimCmdlets.InvokeCimMethodCommand

我似乎找不到在几个地方看过的答案,几个月前我已经看到人们开始遇到这个问题,但是我找不到答案,任何建议都将受到赞赏

我的最终目标是编写一个脚本,在该脚本中导入电源计划,然后将其激活,然后让导入部分在最后一点工作良好。 $ p包含我导入的计划,出于测试目的,我在默认计划中使用了$ p2。

欢呼,并感谢您提供的任何建议

1 个答案:

答案 0 :(得分:0)

我找到了用于更改电源架构的代码。

Get-CimInstance -N root\cimv2\power -Class win32_PowerPlan | select ElementName, IsActive | ft -a

$p = gwmi -NS root\cimv2\power -Class win32_PowerPlan -Filter "ElementName ='Ultimate Performance'"

$p.Activate()


Get-CimInstance -N root\cimv2\power -Class win32_PowerPlan | select ElementName, IsActive | ft -a

pause

它适用于大多数Windows O / S版本。我有时会收到此错误。

“调用” Activate“的异常:”该方法未在任何类中实现“在第1行char:1 + $ p2.Activate()+ ~~~~~~~~~~~~~~ + CategoryInfo:未指定:(:) [],MethodInvocationException + FullyQualifiedErrorId:WMIMethodException –“