Hello
In a environment where there are multiple VM's which are missing descriptor file and its very hard to find which hard disk vmdk file is missing.
1. VM's are in powered on State.
2. Need to find VM's whose harddisk doesn't consists of .vmdk file.
My idea is to list all VM's and there harddisk with corresponding .vmdk file(descriptor file) . There we find the VM's with no vmdk file will show blank in csv file.
I tried to execute below code but its trimming the harddisk file name and showing vmdk path.
Can some one direct me on correct path please?
foreach ($VM in (Get-VM 'log1' | Sort-Object -Property Name)) {
foreach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)){
$ds = Get-Datastore -Name $HardDisk.Filename.Split(']')[0].TrimStart('[')
$vmdkPath = $HardDisk.Filename.Split(']')[1].TrimStart(' ')
""| select @{N="VM";E={$VM.Name}},
@{N="Hard Disk";E={$HardDisk.Name}},
@{N="Datastore";E={$ds.Name}},
@{N="VMDKpath";E={$vmdkPath}},
@{N="VMDK Size";E={($VM.extensiondata.layoutex.file|?{$_.name -contains $HardDisk.filename.replace(".","-flat.")}).size/1GB}},
@{N="Drive Size";E={$HardDisk.CapacityGB}}
}
}