How to Reboot a Machine via PowerShell
I tried search online for this, however, most of the online answers will ask you to run the following command as an admin
$OperationSystemObject = Get-WmiObject Win32_OperatingSystem -Comp "yourcomputername"
$OperationSystemObject.Win32Shutdown(6)
or
$OperationSystemObject.Reboot()
However, I keep getting an error saying that "Privilege not held"
I even tried to use the credential switch but still not working. Finally, it turns out that it is not me not having the right privilege. It is the thread itself need to have the right permission to shut the machine down. So here is the correct way to do this.
$OperationSystemObject = Get-WmiObject Win32_OperatingSystem -Comp "yourcomputername"
$OperationSystemObject.psbase.Scope.Options.EnablePrivileges = $true
$OperationSystemObject.Win32Shutdown(6)
or
$OperationSystemObject.Reboot()
