# ToolMaking MOL chapter 16.2 question about switching to WMI

**URL:** <https://forums.powershell.org/t/toolmaking-mol-chapter-16-2-question-about-switching-to-wmi/605>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/toolmaking-mol-chapter-16-2-question-about-switching-to-wmi/605 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/toolmaking-mol-chapter-16-2-question-about-switching-to-wmi/605/1 "2011-12-31T18:30:00Z")

</div>

by etolleson at 2013-02-14 06:57:39

> I am new to PS finished the book PV3 MOL and felt pretty good until now, I am letting myself get stuck on the "‘Switching to WMI’ section of 16.2 in the book ToolMaking MOL page 164" for some reason I am not able to get   
> `Invoke-WmiMethod -Class Win32_OperatingSystem -Name REBOOT -ComputerName localhost` to work I have tried several different things. I can get the Invoke-WmiMethod command to work with the help EXAMPLE 2 (notepad) in PS. I am having trouble understanding the error. I tried replacing the code in "listing 16.1" with this code and still no luck. Can you give me sugestions about Invoke-WmiMethod command and ways to troubleshoot the Error that I am receiving and having trouble deciffering fo rsome reason it is:  
> Invoke-WmiMethod : Invalid method Parameter(s)   
> At line:1 char:1  
> + Invoke-WmiMethod -Class Win32\_OperatingSystem -Name REBOOT -ComputerName localho …  
> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
> + CategoryInfo : InvalidOperation: (🙂 [Invoke-WmiMethod], ManagementException  
> + FullyQualifiedErrorId : InvokeWMIManagementException,Microsoft.PowerShell.Commands.InvokeWmiMethod

by etolleson at 2013-02-14 09:51:39

> I found this to work but not really sure why and if it was what the author was suggesting  
> `Get-WmiObject -Class win32_operatingSystem -ComputerName server | Invoke-WmiMethod -name REBOOT`  
> if so great if not what should I have done. Trying to gain a better understanding of how to work with PS and WMI for older version of OS.

by MattG at 2013-02-14 16:36:43

> Great questions. The reason your first example doesn’t work is because the Reboot method is an instance method meaning that you must invoke it from an instance of a WMI class - Win32\_OperatingSystem in your case. As to why this method is not static I don’t know considering you will only ever get a single instance of a Win32\_OperatingSystem class as far as I know. For your first example to work properly, you must call a static method. A good example of a static WMI method is Create in Win32\_Process. To illustrate this, observe the following examples:  
> `Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList calc.exe -ComputerName localhost`and the CIM cmdlet PSv3 equivalent:  
> `Invoke-CimMethod -Class Win32_Process -Name Create -Arguments @{CommandLine='calc.exe'}`To more clearly illustrate that Reboot requires an instance of the Win32\_OperatingSystem class observe the following:  
> `$OperatingSystemInstance = Get-WmiObject -Class Win32_OperatingSystem$OperatingSystemInstance.Reboot()`I hope this helps answer your questions.

by etolleson at 2013-02-15 06:14:42

> Matt thanks for the response. The calc works great and I think I understand the instance that needs to be created. When I first tried the reboot it gave me an error which I found out you could not run it on the localhost or it appears that way anyway as long as I specified a different computer name in the instance it work like a charm. Thanks again for you help.  
>   
> Exception calling "Reboot" : "Privilege not held. "  
> At line:1 char:1  
> + $OperatingSystemInstance.Reboot()  
> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
> + CategoryInfo : NotSpecified: (🙂 , MethodInvocationException  
> + FullyQualifiedErrorId : WMIMethodException

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:02pm UTC](https://forums.powershell.org/t/toolmaking-mol-chapter-16-2-question-about-switching-to-wmi/605/2 "2024-05-16T21:02:47Z")

</div>

Closed on May 16, 2024, 9:02pm UTC


