1

I followed the Scripting Guy instructions from Microsoft but even with this I still get the same error Scripting Guy article

here is my script:
$p2=Get-CimInstance -N root\cimv2\power -Class win32_PowerPlan -Filter "ElementName = 'Balanced'" Invoke-CimMethod -InputObject $p2-MethodName Activate

which results in:
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

I cant seem to find answers I have looked in a few locations, I have seen people start to run into this a few months ago but I could not find an answer any advice would be appreciated

my end goal is to write a script where I import a powerplan and then activate it I have the import part working fine it just this last bit. $p contains my imported plan I used $p2 on a default plan for testing purposes.

cheers and thank you in advance for any advice you can offer

MK Spindel
  • 23
  • 7
  • Just as added information I have also tried Get-WMIobject method found here https://stackoverflow.com/questions/44921510/change-power-plan-to-high-performance but I got this error when trying that: Exception calling "Activate" : "This method is not implemented in any class " At line:1 char:1 + $p2.Activate() + ~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WMIMethodException – MK Spindel Aug 22 '18 at 15:31
  • I can do it via PowerCfg but if someone could let me know how to do it via CIM I would appreciate it as I would like to get better at using CIM – MK Spindel Aug 22 '18 at 16:52
  • Welcome to Stack Overflow. I think the `-Filter` you are using has a mistake. The `=` makes it an assignment, where you want to do a compare. Try `-Filter "ElementName -eq 'Balanced'"`. Also `$p2-MethodName` should be `$p2.MethodName` I gather. – Theo Aug 22 '18 at 18:19
  • Thank you, I took a break from this for a few days now I am back on it so lets get to it: making your changes to the `-filter` syntax actually generated a new error see my object is fine in the $p2 var up to the Invoke section Next I did try the $p2.methodName but it did not work either based on the Microsoft article the way I had it is how that method is to be called but hey I could be wrong I read around, a few others started having this issue as of a win 10 update back in may so this may not be fixable until microsoft solves the issue until then i guess im stuck with the PowerCFG method – MK Spindel Aug 27 '18 at 19:35

1 Answers1

0

I found this code for changing the 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

It works on most flavors of Windows O/S. I get this error sometimes.

"Exception calling "Activate" : "This method is not implemented in any class " At line:1 char:1 + $p2.Activate() + ~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WMIMethodException –"

James
  • 1
  • 1
  • thank you for your answer I had ended up solving this exporting a collection of power-plans set the the way I want and then writing 2 power-shell scripts one to import the plan and a second using the GUID of the plan to set the plan as active, this method however requires a check to ensure you don't have duplicate power-profiles and to remove any duplicates so far its worked for over a year with no errors. – MK Spindel Aug 12 '20 at 14:06