1

I have been looking for a way to restart/shutdown a remote computer with comment from powershell.

The traditional Restart-Computer Cmdlet does not have these options. then somewhere they advised to use the native command for shutdown.exe. But this command does not support the use of credentials like powershell does.

1
  • 1
    The documentation for Restart-Computer indicates that it uses the WMI Win32Shutdown method. You may be able to build upon the similar Win32ShutdownTracker method that does incluse comment and reason. Commented Sep 3, 2017 at 7:11

1 Answer 1

4

On a related research, I stumbled upon the WMI Class Win32_OperatingSystem which comes with a method Win32ShutdownTracker.

The documentation for the Win32Shutdowntracker() method is available here: https://msdn.microsoft.com/en-us/library/aa394057(v=vs.85).aspx

It takes four parameters as explained below:

So the code to Force Restart a remote machine becomes:

(Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer).Win32Shutdowntracker(0, "This is a custom comment", 0x00000000, 6)

Adding Credentials through a PScredential object is now easy:

(Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer -Credential $CustomCredentials).Win32Shutdowntracker(0, "This is a custom comment", 0x00000000, 6)
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.