VMware Cloud Community
krish10
Contributor
Contributor

Require powercli script to unmount VMFS datastores from multiple ESXi servers

HI,

We have 80 datastores and these are attached to many ESXi servers. But we need to unmount these datastores only from two ESXi servers. Is there any script that can unmount these from only two servers.

Labels (1)
0 Kudos
1 Reply
LucD
Leadership
Leadership

Would something like this work for you?

Get-VMHost -Name esx1*, esx2* -PipelineVariable esx |
ForEach-Object -Process {
    Get-Datastore -RelatedObject $esx -PipelineVariable ds | 
    ForEach-Object -Process {
        $storSys = Get-View -Id $esx.ExtensionData.ConfigManager.StorageSystem
        $storSys.UnmountVmfsVolume($ds.ExtensionData.Info.vmfs.uuid)
    }
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos