HOWTO: Power on your IPMI connected computer using PowerShell

As part of my VMware home lab setup I wanted to be able to run a PowerCLI/PowerShell script to Power On/Off my hosts as required. The first objective was being able to power the hosts on using their IPMI interfaces.

Thankfully the Microsoft PowerShell has something that does the job quite nicely called Physical Computer System View (PCSV) Device Cmdlets.

Using Get-PcsvDevice

Using the Get-PcsvDevice command interactively will require you to provide an IP Address/Hostname, a protocol (such as IPMI) and a set of credentials.

Just using Get-PcsvDevice <ip address> will immediately prompt you to provide with the Windows PowerShell credential request dialog.

Even when you get passed this initial dialog, you will then need to supply the Management Protocol to be used.

However, within a PowerShell script, you can easily provide all the relevant information on a command line.

Whoa wait another goddamn second, how do i created an encrypted password to be able to create the credential object to be able to power on my server via IPMI? Well that’s easy too… I’ll call my password object $EncryptedPassword.

Now like most PowerShell cmdlets you use a combination of Get-PcsvDevice and pipe the output into Start-PcsvDevice, Restart-PcsvDevice or Stop-PcsvDevice. If you then also add some text out to the console to show what your actually doing… it may end up looking like this.

To call that function within the PowerShell script you would just use:

StartHost "<host name>" "<IPMI address>" "<user>" "<password>"

Note: the <host name> variable is only passed to the function to enable descriptive output.

I’m sure the PowerShell Wizards may be able to make the above code more efficient, but for my homelab environment at my current PowerShell skill level, it does the job (as part of a wider homelab startup script).