Thursday, September 22, 2016

Q & A

Question:

One of customers ran a Rouge power cli script and now we have a huge number of VMs with missing vmdk discriptor. Is they a power cli way find out what is broke?

Answer:

Try this it will provide vm with harddisk details with size and missing vmdk will show blank in .csv file...there we can sort easily

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}}
}
}

No comments:

Post a Comment