To restart multiple computers with PowerShell and without relying on functionality of the remote operating system, you can use the PCSVDevice module. The module contains several useful cmdlets for out-of-band management and supports the IPMI protocol.

Sometimes you have to shut down a large number of servers due to outages, or you have to restart multiple servers synchronously because of an update to an interdependent application. Out-of-band management is one method we can use to do this.

Out-of-band management with PowerShell

Out-of-band management allows system administrators to access servers via protocols such as the Intelligent Platform Management Interface (IPMI) to perform actions outside of the operating system (OS) a server is running. Using IPMI takes place via a baseboard management controller (BMC) that can be integrated into or separate from the motherboard on a system.

For instance, if a server is powered off and you would like to power it back on, you can use IPMI to send a "power on" command as long as there is a network connection online to the BMC. Examples of BMCs are the Integrated Dell Remote Access (iDRAC) or HP Integrated Lights Out (iLO) cards. While this technology is not new, PowerShell actually has a module, Pcsvdevice, specifically designed for out-of-band management.

PcsvDevice cmdlets

To see what cmdlets are available, we use Get-Command:

Get-Command -Module PcsvDevice
Displaying the cmdlets of the PcsvDevice module

Displaying the cmdlets of the PcsvDevice module

Start-PcsvDevice, Stop-PcsvDevice, and Restart-PcsvDevice are all self-explanatory, but some other interesting cmdlets are part of Windows 10/Server 2016. For instance, to set the network configuration of the IPMI interface, we can run:

Set-PcsvDeviceNetworkConfiguration -IPv4AddressOrigin Static -IPv4Address '172.16.52.11' -IPv4DefaultGateway '172.16.52.1' -IPv4SubnetMask '255.255.255.0'

Booting and powering off systems

In this first example of Start-PcsvDevice, I am going to boot up a physical host running VMware ESXi. This Dell server has an iDRAC interface and is currently powered off. Notice I specify IPMI as the management protocol I use to communicate with the systems. You can also use the Web Services Management (WS-Man) protocol, though I will be using IPMI exclusively in this article.

Start-PcsvDevice -TargetAddress ESXiTest-IPMI -Credential (Get-Credential) ‑ManagementProtocol IPMI

To power down a system, we use the same parameters with Stop-PcsvDevice:

Stop-PcsvDevice -TargetAddress ESXiTest-IPMI -Credential (Get-Credential) -ManagementProtocol IPMI

Restarting multiple servers

Now in this example we want to automate the restarting of multiple servers in our data center. Keep in mind, the beauty of out-of-band management is that the OS installed on a server is irrelevant. So regardless of whether a server is running Windows or Linux, we can use these same cmdlets to power them on.

I have configured the same IPMI user account on each server, so I will be able to authenticate with the same $Credential variable in PowerShell.

First I will put the hosts in a variable, $Computers. I will then use Restart-PcsvDevice with the Foreach-Object cmdlet to boot all of the servers. It would be helpful to have a data source I could query that would provide a dynamic value for all the physical hosts I need. So in this example I will use Get-ADComputer to query all hosts in a particular organizational unit (OU) called "Physical Servers."

$Computers = Get-ADComputer -SearchBase 'OU=Physical Servers,OU=Servers,DC=DOMAIN,DC=COM' -Filter * | select -ExpandProperty Name

Now I will pipe the values in $Computers to the Foreach-Object cmdlet to boot all the hosts. Note I add "-IPMI" to the target address since these iDRAC interfaces refer to the production hostname of the server with -IPMI added:

$Computers | ForEach-Object {Restart-PcsvDevice -TargetAddress ($_ + '-IPMI') -Credential $Credential -ManagementProtocol IPMI -TimeoutSec 10}

Conclusion

Although many organizations are pushing their systems to the cloud, for most, a hybrid setup will be the norm for the foreseeable future. Managing on-premises systems means you need to prepare for unforeseen occurrences that can cause power outages. You may need to power off hundreds or thousands of servers and power them back on quickly due to outages. Out-of-band management is one method you can use to do this.

Subscribe to 4sysops newsletter!

In addition, the cmdlets of the PCSVDevice module come in handy whenever you have to shut down or restart multiple computers without relying on the operating system of the remote systems.

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account