Symptoms for Issue 1
Customers who try to turn off or restart a system, either local or remote, by using the stop-computer command on PowerShell v3.0 and later, will see the following error:
stop-computer : Privilege not held.
At line:1 char:1
+ stop-computer
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (<COMPUTERNAME>:String) [Stop-Computer], ManagementE
+ FullyQualifiedErrorId : StopComputerException,Microsoft.PowerShell.Commands.StopComputerCommand
Workaround for Issue 1
To work around this issue, run the following “shutdown.exe” command to execute power-down and restart operations on local or remote systems:
shutdown.exe [-r] [-s] [-m \\computer]
For more information and command help, run:
shutdown.exe -?
Symptoms for Issue 2
Customer applications using power management methods, such as shutdown or reboot, from the Win32_OperatingSystem class and set the EnablePrivileges attribute to true, may observe the same “Privilege not held” error.
Workaround for Issue 2
- For Example 1 (PowerShell):
$computername= "."
$win32OS = get-wmiobject win32_operatingsystem -computername $computername -EnableAllPrivileges
$win32OS.reboot()
- For Example 2 (C# code):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication
{
public class Program
{
static void Main(string[] args)
{
var mgmtScope = new ManagementScope(
ManagementPath.DefaultPath,
new ConnectionOptions()
{
EnablePrivileges = true
});
var mgmtClass = new ManagementClass(mgmtScope, new ManagementPath("Win32_OperatingSystem"), null);
foreach (ManagementObject mgmtInst in mgmtClass.GetInstances())
{
var mgmtCallResult = mgmtInst.InvokeMethod("Reboot", null, null);
Console.Out.WriteLine("Reboot() Return Value: {0}", mgmtCallResult["ReturnValue"]);
}
}
}
}