VMware Cloud Community
monderick
Enthusiast
Enthusiast

VMs with VMDK disks split among datastores

Anyone have an existing script that will only output VMs with VMDK disks not all on one datastore?  This storage DRS 'keep VMDK disks together' checkbox got undone in our environment and disks were moved all over the map.

thanks

0 Kudos
3 Replies
LucD
Leadership
Leadership

Would this help?

Get-VM | where{$_.DatastoreIdList.Count -gt 1}


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

monderick
Enthusiast
Enthusiast

Thanks LucD, I started down that path but the 'get-datastore' commandlet includes mounted ISO's and not seeing a property to exempt on

came up with the below, it's ugly but seems to work

find vmx registration datastore name:

$VM = get-vm xxxx | select Name,@{N="VMPath";E={$_.ExtensionData.Config.Files.VmPathName}}

$diskreal = $VM.VMPath

$diskfinal = $diskreal.Split( )[0]

get VM harddisks and compare to vmx registration path:

get-harddisk -vm $VM.name | foreach-object {

$harddiskreal = $_.Filename

$harddiskfinal = $harddiskreal.split( )[0]

if ("$harddiskfinal" -ne "$diskfinal") {write-host $harddiskreal is on different datastore than $diskreal}

}

now to clean it up

0 Kudos
LucD
Leadership
Leadership

If SDRS is active, the affinity rule should correct the situation.


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

0 Kudos