VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot

Issue Exporting LUN, VM_IPaddress, Cluster Name, ESXHostName and Folder details

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.

Reply
0 Kudos
4 Replies
MKguy
Virtuoso
Virtuoso

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 $_}}
-- http://alpacapowered.wordpress.com
Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot

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

Reply
0 Kudos
MKguy
Virtuoso
Virtuoso

Works fine for me. Does the VM have RDM LUNs?

-- http://alpacapowered.wordpress.com
Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot

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.

Reply
0 Kudos