I'd be careful with this approach. Since the PowerCLI implementation of ESXCLI seems to have a hard 30min timeout, any datastores that take longer than 30 min to execute unmap (most >2TB in my ex...
See more...
I'd be careful with this approach. Since the PowerCLI implementation of ESXCLI seems to have a hard 30min timeout, any datastores that take longer than 30 min to execute unmap (most >2TB in my experience) will *appear* to error in PowerCLI and it will move onto the next DS. But since it doesn't actually end the unmap execution, one could have 2, 3, 4, etc unmaps all taking place at the same time. If the set of datastores happens to have a consecutive set of datastores all in the same cluster (likely), then the | Select -First 1 approach will likely result in a single host executing all those concurrent unmaps. While the unmaps may not create significant load on the host, depending on the hardware environment, it could place additional load on the storage environment/fabric at a single, particular location which in some heavy-load environments may cause performance issues. My preference is to do something like: $esx = $ds | Get-VMHost | Where {$_.ConnectionState -eq "Connected" -and $_.ExtensionData.Runtime.StandbyMode -eq 'none' -and $_.ExtensionData.Runtime.InMaintenanceMode -eq $false} | Get-Random That way, you're not likely to get the same host for unmaps in the same cluster, thus distributing the load a bit.