O'Reilly logo

Windows PowerShell™ Scripting Guide by Ed Wilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required