EKutsko
Contributor
Contributor

I figured it out...here is what I did.

Connect-VIServer dabwinpvmvc01

$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)) {

      ForEach ($Contact1 in ($VM | Get-Annotation -CustomAttribute "1st Contact" | Sort-Object -Property Name)) {

  ForEach ($Contact2 in ($VM | Get-Annotation -CustomAttribute "2nd Contact" | 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="VMDKpath";E={$HardDisk.FileName}},

          @{N="VMDK Size in GB";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}},

   @{N="1st Contact";E={$Contact1.value}},

   @{N="2nd Contact";E={$Contact2.value}}

  } 

      }

   }

    }

  }

}

$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "VmInfo.csv"