VMware Cloud Community
esxi1979
Expert
Expert
Jump to solution

vcenter vm lable Vs dns name

While doing server inventory i found that a vm has vcenter lable & dns name mis-match. ideally they should be same to avoid confion.

Can with powercli we can find such mis-matched records

thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Note that I added a test to check if $_.guest.hostname is not empty.

Get-View -ViewType "VirtualMachine" -Property @("Name", "guest.hostname", "config.name") |`

Where-Object {$_.guest.hostname -and ($_.guest.hostname.Split('.')[0] -ne $_.config.name) }|`

Select-Object -Property Name,  @{N="DNS name";E={$_.guest.hostname}},  @{N="Configured OS name";E={$_.config.name}}

If you also want to list the VMs where $_.guest.hostname is empty (powered off, VMware Tools not installed...), you can do

Get-View -ViewType "VirtualMachine" -Property @("Name", "guest.hostname", "config.name") |`

Where-Object {!$_.guest.hostname -or ($_.guest.hostname -and ($_.guest.hostname.Split('.')[0] -ne $_.config.name))}|`

Select-Object -Property Name,  @{N="DNS name";E={$_.guest.hostname}},  @{N="Configured OS name";E={$_.config.name}}


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

View solution in original post

0 Kudos
2 Replies
esxi1979
Expert
Expert
Jump to solution

i did this

Get-View -ViewType "VirtualMachine" -Property @("Name", "guest.hostname", "config.name") |`

Where-Object {($_.guest.hostname -ne $_.config.name) }|`

Select-Object -Property Name,  @{N="DNS name";E={$_.guest.hostname}},  @{N="Configured OS name";E={$_.config.name}}

problem is the dns name for unix is with FQDN vs the lable being without fqdn .. can we sort this somehow

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

Note that I added a test to check if $_.guest.hostname is not empty.

Get-View -ViewType "VirtualMachine" -Property @("Name", "guest.hostname", "config.name") |`

Where-Object {$_.guest.hostname -and ($_.guest.hostname.Split('.')[0] -ne $_.config.name) }|`

Select-Object -Property Name,  @{N="DNS name";E={$_.guest.hostname}},  @{N="Configured OS name";E={$_.config.name}}

If you also want to list the VMs where $_.guest.hostname is empty (powered off, VMware Tools not installed...), you can do

Get-View -ViewType "VirtualMachine" -Property @("Name", "guest.hostname", "config.name") |`

Where-Object {!$_.guest.hostname -or ($_.guest.hostname -and ($_.guest.hostname.Split('.')[0] -ne $_.config.name))}|`

Select-Object -Property Name,  @{N="DNS name";E={$_.guest.hostname}},  @{N="Configured OS name";E={$_.config.name}}


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

0 Kudos