1

我按照 Microsoft 的 Scripting Guy 说明进行操作,但即便如此,我仍然收到相同的错误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 以进行测试。

干杯,并提前感谢您提供的任何建议

4

1 回答 1

0

我找到了用于更改 Power Schema 的代码。

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。我有时会收到此错误。

“异常调用“激活”:“此方法未在任何类中实现”在 line:1 char:1 + $p2.Activate() + ~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified : (:) [], MethodInvocationException + FullyQualifiedErrorId : WMIMethodException –”

于 2019-03-20T15:59:26.010 回答