Playing with PowerShell

I use powershell all the time now to manage VMware, with the PowerCLI commandlets you can achieve a lot and it matches Alan Kay’s motto

Simple things should be simple, complex things should be possible.

The simple: I want to go and set all the LUNs in VMware to use “RoundRobin” as the MultipathPolicy

My first attempt was,

[powershell]Get-VMHost | Get-ScsiLun | Set-ScsiLun -MultipathPolicy “RoundRobin”[/powershell]

Loop through the hosts, loop though each of its LUNs, set MultipathPolicy to “RoundRobin”

Which works, but was taking ages. I was about to make separate scripts for each server when I realised I was not quite doing what I wanted with that script. I really wanted to:

Loop through the hosts, loop though each of its LUNs, if it was not already RoundRobin, set MultipathPolicy to “RoundRobin”

[powershell]Get-VMHost | Get-ScsiLun | where {$_.MultipathPolicy -ne “RoundRobin”} | Set-ScsiLun -MultipathPolicy “RoundRobin”[/powershell]

Which ran loads faster as the “set” command still ran and took a while even if you were setting it to what it already was.

The Complex:

I took the wonderful vcheck script and made it run every night. Great email overview of the virtual infrastructure each morning.