It seems I am 3 years late to the party but this has been something I have been looking for a while. The traditional Shutdown.exe method however, does not really support the use of credentials. I could perhaps use cmdkey to cache a credential and trick it to use credential in that manner. So in my quest for a better way, I stumbled upon the Win32_OperatingSystem WMI Class which comes with a Method called Win32ShutdownTracker. Here is the documentation for it: https://msdn.microsoft.com/en-us/library/aa394057(v=vs.85).aspx
If we take a look, running the below code will show us the format to be used.
(Get-WmiObject Win32_OperatingSystem).Win32Shutdowntracker
System.Management.ManagementBaseObject Win32ShutdownTracker(System.UInt32 Timeout, System.String Comment, System.UInt32 ReasonCode, System.Int32 Flags)
Going by the information so far, we can provide an Integer Timeout, a string comment , an integer Reason Code and the Flag which will actually perform the action.
A list of reason codes can be found here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa376885(v=vs.85).aspx
The flags are mentioned in the Win32Shutdowntracker documentation mentioned earlier. Now we have everything we need. So, the final code to restart a machine would look like
(Get-WmiObject Win32_OperatingSystem -ComputerName $Computer).Win32Shutdowntracker(0, "This is my Custom Comment", 0x00000000 , 6)
Adding a credential now just becomes easier.
(Get-WmiObject Win32_OperatingSystem -ComputerName $Computer -Credential $PSCredential).Win32Shutdowntracker(2, "This is my custom Comment", 0x00000000 , 6)
Where $PScredential is a PScredential Object.
Running this will give a result like this:
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ReturnValue : 0
PSComputerName :
The Return Value of 0 indicates successful execution.