Reply to Message

View discussion in a popup

Replying to:
LucD
Leadership
Leadership

Try like this

$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
 
ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {
   
ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {
     
ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)) {
       
"" | Select-Object -Property @{N="VM";E={$VM.Name}},
         
@{N="Datacenter";E={$Datacenter.name}},
         
@{N="Cluster";E={$Cluster.Name}},
         
@{N="Hard Disk";E={$HardDisk.Name}},
         
@{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}},
         
@{N="CanonicalName";E={
            [
string]::Join(',',((Get-Datastore -Name ($HardDisk.FileName.Split("]")[0].TrimStart("["))).Extensiondata.Info.Vmfs.Extent | %{$_.DiskName}))}},
         
@{N="VMDKpath";E={$HardDisk.FileName}}
      }
    }
  }
}
$VmInfo


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