Shutting Down or Rebooting a Remote Computer

If you are renaming a computer or joining a domain, then you will need to be able to either shut down or reboot a remote computer. To do this, you can use WMI to perform both tasks. In the ShutdownRebootComputer.ps1 script, use the shutdown() and the reboot() methods from the Win32_OperatingSystem WMI class. To determine which method to call, use the -a parameter in the script to specify the action to take.

The first line of the ShutdownRebootComputer.ps1 script defines the param statement. Once again, specify multiple default values as shown here:

param(
      $computer="localhost",
      $user = "administrator",
      $password,
      $a,
      $help
    )

Next, use the funhelp function to print a help string if requested by the user. ...

Get Windows PowerShell™ Scripting Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.