Reply to Message

View discussion in a popup

Replying to:
vin01
Expert
Expert

Thanks for your 'VMX Raiders Revisited' Script. With the help of that script I tried this variation and tested on single VM. It worked.

Any modifications will be helpful for faster and accurate output.

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(' ')

$vmdkPathtrim =$vmdkPath.split('/')[1].trimstart('/')

# Set up Search for .VMDK Files in Datastore

New-PSDrive -Name TgtDS -Location $ds -PSProvider VimDatastore -Root '\' | Out-Null

$vmdksearch = @(Get-ChildItem -Path TgtDS: -Recurse | `

where {$_.FolderPath -notmatch ".snapshot" -and $_.Name -like "$vmdkPathtrim"})

Remove-PSDrive -Name TgtDS

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

@{N="VMDK Exist In Datastore";E={$vmdksearch}}

}

}

Regards Vineeth.K

View solution in original post

Reply
0 Kudos