Hello! It seems bringing old threads back from the dead is not popular here, so I will make a new one.
I'm trying to figure out how to add an additional output column to this report, specifically DNS Name found in vSphere. I've tried pulling several other examples from DNS Name only reports with no luck. The column ends up blank on the final report.
For example
@{N='DnsName';E={$vm.ExtensionData.Guest.Hostname}},
Here's the report script I'm referring to made by LucD
$report = foreach($vc in $global:defaultviservers){
foreach($vm in (Get-View -ViewType VirtualMachine -Property Name,runtime.powerState,runtime.consolidationNeeded,Guest.net,Config.Hardware.numCPU,Config.Hardware.MemoryMB,
Runtime.Host,Guest.GuestFullName, Config.GuestFullName,Parent,ResourcePool,Config.Hardware.Device,Config.version,Config.Tools.ToolsVersion,guest.toolsversionstatus,
Config.Files.VMPathName,Config.Template -Server $vc )){
if($vm.Config.Template){
$t = Get-View -Id (Get-View $vm.Runtime.Host).Parent
}
else{
$t = Get-View $vm.ResourcePool -Property Name,Parent -Server $vc
while($t.getType().Name -eq "ResourcePool"){
$t = Get-View $t.Parent -Property Name,Parent -Server $vc
}
}
if($t.GetType().Name -eq "ClusterComputeResource"){
$cluster = $t.Name
}
else{
$cluster = "Stand Alone Host"
}
while($t.getType().Name -ne "Datacenter"){
$t = Get-View $t.Parent -Property Name,Parent -Server $vc
}
$datacenter = $t.Name
$vm.Config.Hardware.Device | where {$_ -is [VMware.Vim.VirtualDisk]} |
Select @{N="VM";E={$vm.Name}},
@{N='powerState';E={$vm.runtime.powerState}},
@{N='IP';E={[string]::Join(',',($vm.Guest.Net | %{$_.IpAddress | where{$_.Split('.').Count -eq 4} | %{$_}}))}},
@{N='NumCPU';E={$vm.config.Hardware.NumCpu}},
@{N='Memory GB';E={$vm.Config.Hardware.MemoryMB| %{[math]::Round($_/1kb,2)}}},
@{N='vCenter';E={$vc.Name}},
@{N='VMHost';E={$script:esx = Get-View -Id $vm.Runtime.Host -Server $vc ; $script:esx.name}},
@{N='GuestOS';E={$vm.Guest.GuestFullName}},
@{N='ConfiguredOS';E={$vm.Config.GuestFullName}},
#@{N="Folder";E={$path}},
@{N="Cluster";E={$cluster}},
@{N="Datacenter";E={$datacenter}},
@{N="Scsi";E={$_.UnitNumber}},
@{N="Hard Disk";E={$_.DeviceInfo.Label}},
@{N="Disk datastore";E={$_.Backing.Filename.Split(']')[0].TrimStart('[')}},
@{N='Needs Consolidation';E={$vm.Runtime.consolidationNeeded}},
@{N="Disk capacity GB";E={$_.CapacityInKB| %{[math]::Round($_/1MB,2)}}},
@{N="Disk type";E={
if($_.Backing.GetType().Name -match "flat"){
"Flat"
}
else{
$_.Backing.CompatibilityMode
}}},
@{N='DeviceName';E={
if($_.Backing.GetType().Name -match 'raw'){
$_.Backing.DeviceName
}
else{
$script:lunnaa = (Get-View -Id $_.Backing.Datastore -Server $vc ).Info.Vmfs.Extent[0].DiskName
$script:lun = $script:esx.Config.StorageDevice.ScsiLun | where{$_.CanonicalName -eq $script:lunnaa}
$script:lun.Descriptor | where{$_.Id -match 'vml.'} | Select -ExpandProperty Id
}}},
@{N='LUN NAA';E={
if($_.Backing.GetType().Name -match 'raw'){
$lunUuid = $_.Backing.LunUuid
$script:lun = $script:esx.Config.StorageDevice.ScsiLun | where{$_.Uuid -eq $lunUuid}
$script:lun.CanonicalName
}
else{
$script:lunnaa
}}},
@{N='LUN ID';E={
$dev = $script:esx.Config.StorageDevice.PlugStoreTopology.Device | where {$_.Lun -eq $script:lun.Key}
$script:esx.Config.StorageDevice.PlugStoreTopology.Path | where {$_.Device -eq $dev.Key} |
Select -First 1 -ExpandProperty LunNumber
}},
@{N='VMConfigFile';E={$VM.config.files.VMpathname}},
@{N='VMDKPath';E={$_.Backing.FileName}},
@{N="HW Version";E={$vm.Config.version}},
@{N="VMware Tools version";E={$vm.Config.Tools.ToolsVersion}},
@{N="Tools Status";E={$vm.guest.toolsversionstatus}},
@{N="NIC Name";E={($vm.config.hardware.device | where {($_.DeviceInfo.Label -like "Network*")}).DeviceInfo.Label}},
@{N="Mac"; E={($vm.Config.Hardware.Device | where{$_.DeviceInfo.Label -like "Network*"}).MacAddress}},
@{N="Portgroup"; E={
$nic = $vm.Config.Hardware.Device | where{$_.DeviceInfo.Label -like "Network*"}
[string]::Join(',',(
$nic | %{
if($_.DeviceInfo.Summary -notmatch 'DVSwitch'){
$_.DeviceInfo.Summary
}
else{
Get-View -ViewType DistributedVirtualPortgroup -Property Name -Filter @{'Key'=$_.Backing.Port.PortgroupKey} -Server $vc |
Select -ExpandProperty Name
}}))}}
}
}
$report | Export-Csv report.csv -NoTypeInformation -UseCulture
This script works with the objects returned by Get-View, vSphere objects.
That means you there is no need to use the ExtensionData property.
Just use
@{N = 'DnsName'; E = { $vm.Guest.Hostname } },
The Get-View cmdlet uses the names on the Property parameter to determine for which properties to pass values.
So you will have to the Guest.HostName property.
foreach ($vm in (Get-View -ViewType VirtualMachine -Property Name, runtime.powerState, runtime.consolidationNeeded, Guest.net, Config.Hardware.numCPU, Config.Hardware.MemoryMB,
Runtime.Host, Guest.GuestFullName, Config.GuestFullName, Parent, ResourcePool, Config.Hardware.Device, Config.version, Config.Tools.ToolsVersion, guest.toolsversionstatus,
Config.Files.VMPathName, Config.Template, Guest.HostName -Server $vc )) {
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This script works with the objects returned by Get-View, vSphere objects.
That means you there is no need to use the ExtensionData property.
Just use
@{N = 'DnsName'; E = { $vm.Guest.Hostname } },
The Get-View cmdlet uses the names on the Property parameter to determine for which properties to pass values.
So you will have to the Guest.HostName property.
foreach ($vm in (Get-View -ViewType VirtualMachine -Property Name, runtime.powerState, runtime.consolidationNeeded, Guest.net, Config.Hardware.numCPU, Config.Hardware.MemoryMB,
Runtime.Host, Guest.GuestFullName, Config.GuestFullName, Parent, ResourcePool, Config.Hardware.Device, Config.version, Config.Tools.ToolsVersion, guest.toolsversionstatus,
Config.Files.VMPathName, Config.Template, Guest.HostName -Server $vc )) {
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ah perfect, thank you so much! o/