Hi,
Can some help me getting this script to pull the few fields, I have trouble getting those
Get-VM crpt01 | Get-HardDisk |
Select @{N='VMName';E={$_.Parent.Name}},
@{N='HDName';E={$_.Name}}, `
@{N='DiskType';E={$_.DiskType}}, `
@{N='HDFormat';E={$_.StorageFormat}}, `
@{N='HDCapacity';E={$_.CapacityGB}}, `
@{N='NAA';E={$_.ScsiCanonicalName}}, `
$lun = Get-ScsiLun -VmHost $row.VMHost -CanonicalName $row.HDDisplayName
@{N='LUN';E={$_.$row.LUN = $lun.RuntimeName.SubString($lun.RuntimeName.LastIndexof("L")+1)}}, `
@{N="IP Address";E={@($_.guest.IPAddress[0])}}, `
@{N="Cluster";E={Get-Cluster -VM $_}}, `
@{N="ESX Host";E={Get-VMHost -VM $_}}, `
@{N="Folder";E={$_.Folder.Name}}, `
@{N="Datastore";E={Get-Datastore -VM $_}} | `
Export-Csv C:\test001.csv -NoTypeInformation -UseCulture
I am not able to retrieve the marked parameters, they are retrieving null.
With that piping your $_ variable contains the disk objects, and not the VM object. This is why most of the latter values return blank values (use $_.Parent).
Try this:
Get-VM crpt01 | Get-HardDisk |
Select @{N='VMName';E={$_.Parent.Name}},
@{N='HDName';E={$_.Name}},
@{N='DiskType';E={$_.DiskType}},
@{N='HDFormat';E={$_.StorageFormat}},
@{N='HDCapacity';E={$_.CapacityGB}},
@{N='NAA';E={(Get-ScsiLun -Datastore ($_.Parent | Get-Datastore)).CanonicalName}},
@{N='LUN';E={(Get-ScsiLun -Datastore ($vm | Get-Datastore)).RunTimeName | % {$_[-1]}}},
@{N="IP Address";E={@($_.Parent.guest.IPAddress[0])}},
@{N="Cluster";E={Get-Cluster -VM $_.Parent}},
@{N="ESX Host";E={Get-VMHost -VM $_.Parent}},
@{N="Folder";E={$_.Parent.Folder.Name}},
@{N="Datastore";E={Get-Datastore -VM $_}}
Hi,
I still have issue with below, NAA is not corressponding with Harddisks, it just lists in oneline also LUN shows blank.
@{N='NAA';E={(Get-ScsiLun -Datastore ($_.Parent | Get-Datastore)).CanonicalName}},
@{N='LUN';E={(Get-ScsiLun -Datastore ($vm | Get-Datastore)).RunTimeName | % {$_[-1]}}},
Works fine for me. Does the VM have RDM LUNs?
Yes, VM has RDM, but NAA is not matching to the VMDK Harddisk and RDM Disks
Instead NAA is displaying all in one line.
LUN number is showing blank for them.
Rest are showing fine.