You can use the next script to retrieve the working directories of all the virtual machines sorted by directory. If a machine has harddisks on multiple datastores the script shows them all.
Get-VM | ForEach-Object {
$VM = $_
$VM.HardDisks | ForEach-Object {
$HardDisk = $_
$Report = "" | select-Object Directory,VM
$Report.Directory = $HardDisk.FileName.Split("/")[0]
$Report.VM = $VM.Name
$Report
}
} | Sort-Object -property Directory -Unique
Because the forum software has problems with square brackets, and square brackets are used in the script, I attach the script to this post also.
Regards, Robert