Powershell: Shutdown/Reboot Server using WMI. Privilege Not Held

This one only took me a couple of minutes to debug, but it gave me a laugh.

Watcha Doin’ BRUCE ?
I was using the following command from within Powershell to reboot my favourite server, BRUCE

$server = get-wmiobject -computer BRUCE -class Win32_OperatingSystem
$server.reboot()

Powershell told me rack off. Specifically it was chucking an exception with Error: Privilege Not Held. Rude old Powershell.

This error had me briefly puzzled because I KNEW that the Powershell account making the WMI call had admin privileges on BRUCE.

Then I realised that the script itself was running on BRUCE. i.e. I was running a script that was trying to shut down the server on which it was running. This may not be advisable.

So I ran the script on a different server, NARELLE, and tried to reboot BRUCE from there. Surprise, surprise it worked.

In summary, you will get Privilege Not Held from Powershell WMI if you try to reboot a server on which your script/WMI call is executing. Run your script on a different machine and try again.

Other Things To Avoid
– Sawing off a branch while sitting on it.
Smashing yourself over the head with a Fire Extinguisher.

Advertisements

Tags: ,

2 Responses to “Powershell: Shutdown/Reboot Server using WMI. Privilege Not Held”

  1. Bryan Brandt Says:

    Alright, this made me chuckle. Definitely. Thanks a lot; I was searching for an answer to this, seeing as one of our servers can only still run PS1.0.

    Thanks for your information and helpful advice on things to avoid!
    I for one will never try to saw off a branch whilst sitting on it.

    • baraholka1 Says:

      Hi Bryan,

      Its great to grow in wisdom together 🙂
      Something else to watch out for – best not to stuff Brazilian Fire Ants up your nose…

      Rgds,

      Barra

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: