build 6ddc7a35 | content blog-content@417154f · 338 posts | profiles 32 · corpus 315 | ● 0 skipped | format run

$ soultec get post/powercli-find-differences-between-dns-name-and-vm-display-name -o yaml$ soultec get post/powercli-find-differences-between-dns-name-and-vm-display-name -o json$ soultec get post/powercli-find-differences-between-dns-name-and-vm-display-name -o toml$ soultec get post/powercli-find-differences-between-dns-name-and-vm-display-name -o xml$ python3 powercli-find-differences-between-dns-name-and-vm-display-name.pyPS> ./powercli-find-differences-between-dns-name-and-vm-display-name.ps1$ go run powercli-find-differences-between-dns-name-and-vm-display-name.go$ node powercli-find-differences-between-dns-name-and-vm-display-name.js

apiVersion: soultec.ch/v1kind: Postmetadata: name: powercli-find-differences-between-dns-name-and-vm-display-name locale: en labels: author: dario-doerflinger series: scripting capability/automation: 1.81 vendor/vmware: 0.98 annotations: source: blog-content/posts/en/powercli-find-differences-between-dns-name-and-vm-display-name.md route: /en/insights/powercli-find-differences-between-dns-name-and-vm-display-name/ schema: /nerd/schema/posts.json markdown: /en/insights/powercli-find-differences-between-dns-name-and-vm-display-name.mdspec: title: Find differences between DNS-Name and VM Display-Name date: 2014-12-09 author: dario-doerflinger locale: en summary: >- My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client. capabilities: [automation] vendors: [vmware] series: scripting legacySlug: powercli-find-differences-between-dns-name-and-vm-display-name migrated: 2026-08-24 comments: 1 draft: false sections: - body: | My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client. The reason is simple: our backup solution sometimes has troubles when those values differ. And in some rare occassion we cannot find the VM on which we should be doing support on because the client only knows the dns-name and we can only find VMs by displayname. Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts). Long story, short script: ```powershell $OutArray = @() $vms = Get-VM foreach ($vm in $vms) { $myobj = "" | Select "VM", "DNSname", "Status" $guest = Get-VMGuest -VM $vm $pat = "." $vmname = $guest.VmName $hostname = $guest.HostName $myobj.VM = $vmname $myobj.DNSname = $hostname if ( $hostname -ne $null) { $pos = $hostname.IndexOf(".") if ( $pos -ne "-1") { $hostname = $hostname.Substring(0, $pos) } if ( $hostname -ne $vmname ) { Write-Host -ForegroundColor Red "---> The VM: $vm has different DNS and Display-Name!" Write-Host -ForegroundColor Red "---->Hostname: " $hostname Write-Host -ForegroundColor Red "---->VmName: "$vmname $myobj.Status = "Not OK!" } Else { Write-Host -ForegroundColor Green "---> The VM: $vm has identical Names." $myobj.Status = "OK!" } } Else { Write-Host -ForegroundColor Yellow "---> The VM: $vm is not powered-on. Hostname cannot be found in this state!" $myobj.Status = "N/A" } Clear-variable -Name hostname Clear-variable -Name vmname $OutArray += $myobj } $OutArray | Export-Csv "c:\tmp\name_vs_dns_$vcenter.csv" ``` the script connects to a vcenter server of your choice (fill the $vcenter variable!) and then reads out all the vms. it then goes through each vm and gets the guest object of each VM. after that we simply put together our values into variables. since dns names always differ from hostnames when dns is fqdn, I go ahead and count the dots (.) in the dns-name. if there are some, they will be cut away, otherwise it's fine. if the dns-hostname is $null it means that the VM is powered off or doesn't have the necessary tools installed. this is one of my first powershell scripts, so I guess I could have made it work with a few less variables, but hey, it works.. 🙂status: corpus: 315 comments: 1 alsoLike: - {ref: posts/vmware-explore-las-vegas-hackathon-2025, score: 1.00} - {ref: posts/vmware-hackathon-2024-project, score: 1.00} - {ref: solutions/vmware/vmware-cloud-foundation/addon/business-operations, score: 0.60} search: /en/search.json
{ "apiVersion": "soultec.ch/v1", "kind": "Post", "metadata": { "name": "powercli-find-differences-between-dns-name-and-vm-display-name", "locale": "en", "labels": { "author": "dario-doerflinger", "series": "scripting", "capability/automation": 1.81, "vendor/vmware": 0.98 }, "annotations": { "source": "blog-content/posts/en/powercli-find-differences-between-dns-name-and-vm-display-name.md", "route": "/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name/", "schema": "/nerd/schema/posts.json", "markdown": "/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name.md" } }, "spec": { "title": "Find differences between DNS-Name and VM Display-Name", "date": "2014-12-09", "author": "dario-doerflinger", "locale": "en", "summary": "My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client.", "capabilities": [ "automation" ], "vendors": [ "vmware" ], "series": "scripting", "legacySlug": "powercli-find-differences-between-dns-name-and-vm-display-name", "migrated": "2026-08-24", "comments": 1, "draft": false, "sections": [ { "body": "My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client. The reason is simple: our backup solution sometimes has troubles when those values differ. And in some rare occassion we cannot find the VM on which we should be doing support on because the client only knows the dns-name and we can only find VMs by displayname. \nUpdate: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts).\n\nLong story, short script:\n\n```powershell\n$OutArray = @()\n\n$vms = Get-VM\nforeach ($vm in $vms)\n{\n$myobj = \"\" | Select \"VM\", \"DNSname\", \"Status\"\n$guest = Get-VMGuest -VM $vm\n$pat = \".\"\n$vmname = $guest.VmName\n$hostname = $guest.HostName\n$myobj.VM = $vmname\n$myobj.DNSname = $hostname\nif ( $hostname -ne $null)\n{\n$pos = $hostname.IndexOf(\".\")\nif ( $pos -ne \"-1\")\n{\n$hostname = $hostname.Substring(0, $pos)\n}\nif ( $hostname -ne $vmname )\n{\nWrite-Host -ForegroundColor Red \"---> The VM: $vm has different DNS and Display-Name!\"\nWrite-Host -ForegroundColor Red \"---->Hostname: \" $hostname\nWrite-Host -ForegroundColor Red \"---->VmName: \"$vmname\n$myobj.Status = \"Not OK!\"\n}\nElse\n{\nWrite-Host -ForegroundColor Green \"---> The VM: $vm has identical Names.\"\n$myobj.Status = \"OK!\"\n}\n}\nElse\n{\nWrite-Host -ForegroundColor Yellow \"---> The VM: $vm is not powered-on. Hostname cannot be found in this state!\"\n$myobj.Status = \"N/A\"\n}\nClear-variable -Name hostname\nClear-variable -Name vmname\n$OutArray += $myobj\n}\n$OutArray | Export-Csv \"c:\\tmp\\name_vs_dns_$vcenter.csv\"\n```\n\nthe script connects to a vcenter server of your choice (fill the $vcenter variable!) and then reads out all the vms. it then goes through each vm and gets the guest object of each VM. after that we simply put together our values into variables. \nsince dns names always differ from hostnames when dns is fqdn, I go ahead and count the dots (.) in the dns-name. if there are some, they will be cut away, otherwise it's fine. if the dns-hostname is $null it means that the VM is powered off or doesn't have the necessary tools installed. \nthis is one of my first powershell scripts, so I guess I could have made it work with a few less variables, but hey, it works.. 🙂" } ] }, "status": { "corpus": 315, "comments": 1, "alsoLike": [ { "ref": "posts/vmware-explore-las-vegas-hackathon-2025", "score": "1.00" }, { "ref": "posts/vmware-hackathon-2024-project", "score": "1.00" }, { "ref": "solutions/vmware/vmware-cloud-foundation/addon/business-operations", "score": "0.60" } ], "search": "/en/search.json" }}
apiVersion = "soultec.ch/v1"kind = "Post"[metadata]name = "powercli-find-differences-between-dns-name-and-vm-display-name"locale = "en"[metadata.labels]author = "dario-doerflinger"series = "scripting""capability/automation" = 1.81"vendor/vmware" = 0.98[metadata.annotations]source = "blog-content/posts/en/powercli-find-differences-between-dns-name-and-vm-display-name.md"route = "/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name/"schema = "/nerd/schema/posts.json"markdown = "/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name.md"[spec]title = "Find differences between DNS-Name and VM Display-Name"date = 2014-12-09author = "dario-doerflinger"locale = "en"summary = "My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client."capabilities = ["automation"]vendors = ["vmware"]series = "scripting"legacySlug = "powercli-find-differences-between-dns-name-and-vm-display-name"migrated = 2026-08-24comments = 1draft = false[[spec.sections]]body = '''My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client. The reason is simple: our backup solution sometimes has troubles when those values differ. And in some rare occassion we cannot find the VM on which we should be doing support on because the client only knows the dns-name and we can only find VMs by displayname. Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts).Long story, short script:```powershell$OutArray = @()$vms = Get-VMforeach ($vm in $vms){$myobj = "" | Select "VM", "DNSname", "Status"$guest = Get-VMGuest -VM $vm$pat = "."$vmname = $guest.VmName$hostname = $guest.HostName$myobj.VM = $vmname$myobj.DNSname = $hostnameif ( $hostname -ne $null){$pos = $hostname.IndexOf(".")if ( $pos -ne "-1"){$hostname = $hostname.Substring(0, $pos)}if ( $hostname -ne $vmname ){Write-Host -ForegroundColor Red "---> The VM: $vm has different DNS and Display-Name!"Write-Host -ForegroundColor Red "---->Hostname: " $hostnameWrite-Host -ForegroundColor Red "---->VmName: "$vmname$myobj.Status = "Not OK!"}Else{Write-Host -ForegroundColor Green "---> The VM: $vm has identical Names."$myobj.Status = "OK!"}}Else{Write-Host -ForegroundColor Yellow "---> The VM: $vm is not powered-on. Hostname cannot be found in this state!"$myobj.Status = "N/A"}Clear-variable -Name hostnameClear-variable -Name vmname$OutArray += $myobj}$OutArray | Export-Csv "c:\tmp\name_vs_dns_$vcenter.csv"```the script connects to a vcenter server of your choice (fill the $vcenter variable!) and then reads out all the vms. it then goes through each vm and gets the guest object of each VM. after that we simply put together our values into variables. since dns names always differ from hostnames when dns is fqdn, I go ahead and count the dots (.) in the dns-name. if there are some, they will be cut away, otherwise it's fine. if the dns-hostname is $null it means that the VM is powered off or doesn't have the necessary tools installed. this is one of my first powershell scripts, so I guess I could have made it work with a few less variables, but hey, it works.. 🙂'''[status]corpus = 315comments = 1search = "/en/search.json"[[status.alsoLike]]ref = "posts/vmware-explore-las-vegas-hackathon-2025"score = "1.00"[[status.alsoLike]]ref = "posts/vmware-hackathon-2024-project"score = "1.00"[[status.alsoLike]]ref = "solutions/vmware/vmware-cloud-foundation/addon/business-operations"score = "0.60"
<?xml version="1.0" encoding="UTF-8"?><manifest kind="Post"> <apiVersion>soultec.ch/v1</apiVersion> <metadata> <name>powercli-find-differences-between-dns-name-and-vm-display-name</name> <locale>en</locale> <labels> <author>dario-doerflinger</author> <series>scripting</series> <entry key="capability/automation">1.81</entry> <entry key="vendor/vmware">0.98</entry> </labels> <annotations> <source>blog-content/posts/en/powercli-find-differences-between-dns-name-and-vm-display-name.md</source> <route>/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name/</route> <schema>/nerd/schema/posts.json</schema> <markdown>/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name.md</markdown> </annotations> </metadata> <spec> <title>Find differences between DNS-Name and VM Display-Name</title> <date>2014-12-09</date> <author>dario-doerflinger</author> <locale>en</locale> <summary>My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client.</summary> <capabilities> <item>automation</item> </capabilities> <vendors> <item>vmware</item> </vendors> <series>scripting</series> <legacySlug>powercli-find-differences-between-dns-name-and-vm-display-name</legacySlug> <migrated>2026-08-24</migrated> <comments>1</comments> <draft>false</draft> <sections> <section> <body>My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client. The reason is simple: our backup solution sometimes has troubles when those values differ. And in some rare occassion we cannot find the VM on which we should be doing support on because the client only knows the dns-name and we can only find VMs by displayname. Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts).Long story, short script:```powershell$OutArray = @()$vms = Get-VMforeach ($vm in $vms){$myobj = "" | Select "VM", "DNSname", "Status"$guest = Get-VMGuest -VM $vm$pat = "."$vmname = $guest.VmName$hostname = $guest.HostName$myobj.VM = $vmname$myobj.DNSname = $hostnameif ( $hostname -ne $null){$pos = $hostname.IndexOf(".")if ( $pos -ne "-1"){$hostname = $hostname.Substring(0, $pos)}if ( $hostname -ne $vmname ){Write-Host -ForegroundColor Red "---&gt; The VM: $vm has different DNS and Display-Name!"Write-Host -ForegroundColor Red "----&gt;Hostname: " $hostnameWrite-Host -ForegroundColor Red "----&gt;VmName: "$vmname$myobj.Status = "Not OK!"}Else{Write-Host -ForegroundColor Green "---&gt; The VM: $vm has identical Names."$myobj.Status = "OK!"}}Else{Write-Host -ForegroundColor Yellow "---&gt; The VM: $vm is not powered-on. Hostname cannot be found in this state!"$myobj.Status = "N/A"}Clear-variable -Name hostnameClear-variable -Name vmname$OutArray += $myobj}$OutArray | Export-Csv "c:\tmp\name_vs_dns_$vcenter.csv"```the script connects to a vcenter server of your choice (fill the $vcenter variable!) and then reads out all the vms. it then goes through each vm and gets the guest object of each VM. after that we simply put together our values into variables. since dns names always differ from hostnames when dns is fqdn, I go ahead and count the dots (.) in the dns-name. if there are some, they will be cut away, otherwise it's fine. if the dns-hostname is $null it means that the VM is powered off or doesn't have the necessary tools installed. this is one of my first powershell scripts, so I guess I could have made it work with a few less variables, but hey, it works.. 🙂 </body> </section> </sections> </spec> <status> <corpus>315</corpus> <comments>1</comments> <alsoLike> <item> <ref>posts/vmware-explore-las-vegas-hackathon-2025</ref> <score>1.00</score> </item> <item> <ref>posts/vmware-hackathon-2024-project</ref> <score>1.00</score> </item> <item> <ref>solutions/vmware/vmware-cloud-foundation/addon/business-operations</ref> <score>0.60</score> </item> </alsoLike> <search>/en/search.json</search> </status></manifest>
# Code generated by the soultec.ch build. DO NOT EDIT.import jsonPAGE = { "apiVersion": "soultec.ch/v1", "kind": "Post", "metadata": { "name": "powercli-find-differences-between-dns-name-and-vm-display-name", "locale": "en", "labels": { "author": "dario-doerflinger", "series": "scripting", "capability/automation": 1.81, "vendor/vmware": 0.98, }, "annotations": { "source": "blog-content/posts/en/powercli-find-differences-between-dns-name-and-vm-display-name.md", "route": "/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name/", "schema": "/nerd/schema/posts.json", "markdown": "/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name.md", }, }, "spec": { "title": "Find differences between DNS-Name and VM Display-Name", "date": "2014-12-09", "author": "dario-doerflinger", "locale": "en", "summary": "My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client.", "capabilities": ["automation"], "vendors": ["vmware"], "series": "scripting", "legacySlug": "powercli-find-differences-between-dns-name-and-vm-display-name", "migrated": "2026-08-24", "comments": 1, "draft": False, "sections": [ { "body": ( "My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client. The reason is simple: our backup solution sometimes has troubles when those values differ. And in some rare occassion we cannot find the VM on which we should be doing support on because the client only knows the dns-name and we can only find VMs by displayname. \n" "Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts).\n" "\n" "Long story, short script:\n" "\n" "```powershell\n" "$OutArray = @()\n" "\n" "$vms = Get-VM\n" "foreach ($vm in $vms)\n" "{\n" "$myobj = \"\" | Select \"VM\", \"DNSname\", \"Status\"\n" "$guest = Get-VMGuest -VM $vm\n" "$pat = \".\"\n" "$vmname = $guest.VmName\n" "$hostname = $guest.HostName\n" "$myobj.VM = $vmname\n" "$myobj.DNSname = $hostname\n" "if ( $hostname -ne $null)\n" "{\n" "$pos = $hostname.IndexOf(\".\")\n" "if ( $pos -ne \"-1\")\n" "{\n" "$hostname = $hostname.Substring(0, $pos)\n" "}\n" "if ( $hostname -ne $vmname )\n" "{\n" "Write-Host -ForegroundColor Red \"---> The VM: $vm has different DNS and Display-Name!\"\n" "Write-Host -ForegroundColor Red \"---->Hostname: \" $hostname\n" "Write-Host -ForegroundColor Red \"---->VmName: \"$vmname\n" "$myobj.Status = \"Not OK!\"\n" "}\n" "Else\n" "{\n" "Write-Host -ForegroundColor Green \"---> The VM: $vm has identical Names.\"\n" "$myobj.Status = \"OK!\"\n" "}\n" "}\n" "Else\n" "{\n" "Write-Host -ForegroundColor Yellow \"---> The VM: $vm is not powered-on. Hostname cannot be found in this state!\"\n" "$myobj.Status = \"N/A\"\n" "}\n" "Clear-variable -Name hostname\n" "Clear-variable -Name vmname\n" "$OutArray += $myobj\n" "}\n" "$OutArray | Export-Csv \"c:\\tmp\\name_vs_dns_$vcenter.csv\"\n" "```\n" "\n" "the script connects to a vcenter server of your choice (fill the $vcenter variable!) and then reads out all the vms. it then goes through each vm and gets the guest object of each VM. after that we simply put together our values into variables. \n" "since dns names always differ from hostnames when dns is fqdn, I go ahead and count the dots (.) in the dns-name. if there are some, they will be cut away, otherwise it's fine. if the dns-hostname is $null it means that the VM is powered off or doesn't have the necessary tools installed. \n" "this is one of my first powershell scripts, so I guess I could have made it work with a few less variables, but hey, it works.. 🙂" ), }, ], }, "status": { "corpus": 315, "comments": 1, "alsoLike": [ { "ref": "posts/vmware-explore-las-vegas-hackathon-2025", "score": "1.00", }, { "ref": "posts/vmware-hackathon-2024-project", "score": "1.00", }, { "ref": "solutions/vmware/vmware-cloud-foundation/addon/business-operations", "score": "0.60", }, ], "search": "/en/search.json", },}if __name__ == "__main__": print(json.dumps(PAGE, indent=2, ensure_ascii=False))
# Code generated by the soultec.ch build. DO NOT EDIT.$Page = [ordered]@{ apiVersion = 'soultec.ch/v1' kind = 'Post' metadata = [ordered]@{ name = 'powercli-find-differences-between-dns-name-and-vm-display-name' locale = 'en' labels = [ordered]@{ author = 'dario-doerflinger' series = 'scripting' 'capability/automation' = 1.81 'vendor/vmware' = 0.98 } annotations = [ordered]@{ source = 'blog-content/posts/en/powercli-find-differences-between-dns-name-and-vm-display-name.md' route = '/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name/' schema = '/nerd/schema/posts.json' markdown = '/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name.md' } } spec = [ordered]@{ title = 'Find differences between DNS-Name and VM Display-Name' date = '2014-12-09' author = 'dario-doerflinger' locale = 'en' summary = 'My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client.' capabilities = @('automation') vendors = @('vmware') series = 'scripting' legacySlug = 'powercli-find-differences-between-dns-name-and-vm-display-name' migrated = '2026-08-24' comments = 1 draft = $false sections = @( [ordered]@{ body = @'My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client. The reason is simple: our backup solution sometimes has troubles when those values differ. And in some rare occassion we cannot find the VM on which we should be doing support on because the client only knows the dns-name and we can only find VMs by displayname. Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts).Long story, short script:```powershell$OutArray = @()$vms = Get-VMforeach ($vm in $vms){$myobj = "" | Select "VM", "DNSname", "Status"$guest = Get-VMGuest -VM $vm$pat = "."$vmname = $guest.VmName$hostname = $guest.HostName$myobj.VM = $vmname$myobj.DNSname = $hostnameif ( $hostname -ne $null){$pos = $hostname.IndexOf(".")if ( $pos -ne "-1"){$hostname = $hostname.Substring(0, $pos)}if ( $hostname -ne $vmname ){Write-Host -ForegroundColor Red "---> The VM: $vm has different DNS and Display-Name!"Write-Host -ForegroundColor Red "---->Hostname: " $hostnameWrite-Host -ForegroundColor Red "---->VmName: "$vmname$myobj.Status = "Not OK!"}Else{Write-Host -ForegroundColor Green "---> The VM: $vm has identical Names."$myobj.Status = "OK!"}}Else{Write-Host -ForegroundColor Yellow "---> The VM: $vm is not powered-on. Hostname cannot be found in this state!"$myobj.Status = "N/A"}Clear-variable -Name hostnameClear-variable -Name vmname$OutArray += $myobj}$OutArray | Export-Csv "c:\tmp\name_vs_dns_$vcenter.csv"```the script connects to a vcenter server of your choice (fill the $vcenter variable!) and then reads out all the vms. it then goes through each vm and gets the guest object of each VM. after that we simply put together our values into variables. since dns names always differ from hostnames when dns is fqdn, I go ahead and count the dots (.) in the dns-name. if there are some, they will be cut away, otherwise it's fine. if the dns-hostname is $null it means that the VM is powered off or doesn't have the necessary tools installed. this is one of my first powershell scripts, so I guess I could have made it work with a few less variables, but hey, it works.. 🙂'@ } ) } status = [ordered]@{ corpus = 315 comments = 1 alsoLike = @( [ordered]@{ ref = 'posts/vmware-explore-las-vegas-hackathon-2025' score = '1.00' } [ordered]@{ ref = 'posts/vmware-hackathon-2024-project' score = '1.00' } [ordered]@{ ref = 'solutions/vmware/vmware-cloud-foundation/addon/business-operations' score = '0.60' } ) search = '/en/search.json' }}$Page | ConvertTo-Json -Depth 32
// Code generated by the soultec.ch build. DO NOT EDIT.package mainimport ( "encoding/json" "os")var page = map[string]any{ "apiVersion": "soultec.ch/v1", "kind": "Post", "metadata": map[string]any{ "name": "powercli-find-differences-between-dns-name-and-vm-display-name", "locale": "en", "labels": map[string]any{ "author": "dario-doerflinger", "series": "scripting", "capability/automation": 1.81, "vendor/vmware": 0.98, }, "annotations": map[string]any{ "source": "blog-content/posts/en/powercli-find-differences-between-dns-name-and-vm-display-name.md", "route": "/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name/", "schema": "/nerd/schema/posts.json", "markdown": "/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name.md", }, }, "spec": map[string]any{ "title": "Find differences between DNS-Name and VM Display-Name", "date": "2014-12-09", "author": "dario-doerflinger", "locale": "en", "summary": "My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client.", "capabilities": []any{"automation"}, "vendors": []any{"vmware"}, "series": "scripting", "legacySlug": "powercli-find-differences-between-dns-name-and-vm-display-name", "migrated": "2026-08-24", "comments": 1, "draft": false, "sections": []any{ map[string]any{ "body": "My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client. The reason is simple: our backup solution sometimes has troubles when those values differ. And in some rare occassion we cannot find the VM on which we should be doing support on because the client only knows the dns-name and we can only find VMs by displayname. \n" + "Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts).\n" + "\n" + "Long story, short script:\n" + "\n" + "```powershell\n" + "$OutArray = @()\n" + "\n" + "$vms = Get-VM\n" + "foreach ($vm in $vms)\n" + "{\n" + "$myobj = \"\" | Select \"VM\", \"DNSname\", \"Status\"\n" + "$guest = Get-VMGuest -VM $vm\n" + "$pat = \".\"\n" + "$vmname = $guest.VmName\n" + "$hostname = $guest.HostName\n" + "$myobj.VM = $vmname\n" + "$myobj.DNSname = $hostname\n" + "if ( $hostname -ne $null)\n" + "{\n" + "$pos = $hostname.IndexOf(\".\")\n" + "if ( $pos -ne \"-1\")\n" + "{\n" + "$hostname = $hostname.Substring(0, $pos)\n" + "}\n" + "if ( $hostname -ne $vmname )\n" + "{\n" + "Write-Host -ForegroundColor Red \"---> The VM: $vm has different DNS and Display-Name!\"\n" + "Write-Host -ForegroundColor Red \"---->Hostname: \" $hostname\n" + "Write-Host -ForegroundColor Red \"---->VmName: \"$vmname\n" + "$myobj.Status = \"Not OK!\"\n" + "}\n" + "Else\n" + "{\n" + "Write-Host -ForegroundColor Green \"---> The VM: $vm has identical Names.\"\n" + "$myobj.Status = \"OK!\"\n" + "}\n" + "}\n" + "Else\n" + "{\n" + "Write-Host -ForegroundColor Yellow \"---> The VM: $vm is not powered-on. Hostname cannot be found in this state!\"\n" + "$myobj.Status = \"N/A\"\n" + "}\n" + "Clear-variable -Name hostname\n" + "Clear-variable -Name vmname\n" + "$OutArray += $myobj\n" + "}\n" + "$OutArray | Export-Csv \"c:\\tmp\\name_vs_dns_$vcenter.csv\"\n" + "```\n" + "\n" + "the script connects to a vcenter server of your choice (fill the $vcenter variable!) and then reads out all the vms. it then goes through each vm and gets the guest object of each VM. after that we simply put together our values into variables. \n" + "since dns names always differ from hostnames when dns is fqdn, I go ahead and count the dots (.) in the dns-name. if there are some, they will be cut away, otherwise it's fine. if the dns-hostname is $null it means that the VM is powered off or doesn't have the necessary tools installed. \n" + "this is one of my first powershell scripts, so I guess I could have made it work with a few less variables, but hey, it works.. 🙂", }, }, }, "status": map[string]any{ "corpus": 315, "comments": 1, "alsoLike": []any{ map[string]any{ "ref": "posts/vmware-explore-las-vegas-hackathon-2025", "score": "1.00", }, map[string]any{ "ref": "posts/vmware-hackathon-2024-project", "score": "1.00", }, map[string]any{ "ref": "solutions/vmware/vmware-cloud-foundation/addon/business-operations", "score": "0.60", }, }, "search": "/en/search.json", },}func main() { enc := json.NewEncoder(os.Stdout) enc.SetEscapeHTML(false) enc.SetIndent("", " ") if err := enc.Encode(page); err != nil { os.Exit(1) }}
// Code generated by the soultec.ch build. DO NOT EDIT.const page = { apiVersion: "soultec.ch/v1", kind: "Post", metadata: { name: "powercli-find-differences-between-dns-name-and-vm-display-name", locale: "en", labels: { author: "dario-doerflinger", series: "scripting", "capability/automation": 1.81, "vendor/vmware": 0.98, }, annotations: { source: "blog-content/posts/en/powercli-find-differences-between-dns-name-and-vm-display-name.md", route: "/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name/", schema: "/nerd/schema/posts.json", markdown: "/en/insights/powercli-find-differences-between-dns-name-and-vm-display-name.md", }, }, spec: { title: "Find differences between DNS-Name and VM Display-Name", date: "2014-12-09", author: "dario-doerflinger", locale: "en", summary: "My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client.", capabilities: ["automation"], vendors: ["vmware"], series: "scripting", legacySlug: "powercli-find-differences-between-dns-name-and-vm-display-name", migrated: "2026-08-24", comments: 1, draft: false, sections: [ { body: "My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client. The reason is simple: our backup solution sometimes has troubles when those values differ. And in some rare occassion we cannot find the VM on which we should be doing support on because the client only knows the dns-name and we can only find VMs by displayname. \n" + "Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts).\n" + "\n" + "Long story, short script:\n" + "\n" + "```powershell\n" + "$OutArray = @()\n" + "\n" + "$vms = Get-VM\n" + "foreach ($vm in $vms)\n" + "{\n" + "$myobj = \"\" | Select \"VM\", \"DNSname\", \"Status\"\n" + "$guest = Get-VMGuest -VM $vm\n" + "$pat = \".\"\n" + "$vmname = $guest.VmName\n" + "$hostname = $guest.HostName\n" + "$myobj.VM = $vmname\n" + "$myobj.DNSname = $hostname\n" + "if ( $hostname -ne $null)\n" + "{\n" + "$pos = $hostname.IndexOf(\".\")\n" + "if ( $pos -ne \"-1\")\n" + "{\n" + "$hostname = $hostname.Substring(0, $pos)\n" + "}\n" + "if ( $hostname -ne $vmname )\n" + "{\n" + "Write-Host -ForegroundColor Red \"---> The VM: $vm has different DNS and Display-Name!\"\n" + "Write-Host -ForegroundColor Red \"---->Hostname: \" $hostname\n" + "Write-Host -ForegroundColor Red \"---->VmName: \"$vmname\n" + "$myobj.Status = \"Not OK!\"\n" + "}\n" + "Else\n" + "{\n" + "Write-Host -ForegroundColor Green \"---> The VM: $vm has identical Names.\"\n" + "$myobj.Status = \"OK!\"\n" + "}\n" + "}\n" + "Else\n" + "{\n" + "Write-Host -ForegroundColor Yellow \"---> The VM: $vm is not powered-on. Hostname cannot be found in this state!\"\n" + "$myobj.Status = \"N/A\"\n" + "}\n" + "Clear-variable -Name hostname\n" + "Clear-variable -Name vmname\n" + "$OutArray += $myobj\n" + "}\n" + "$OutArray | Export-Csv \"c:\\tmp\\name_vs_dns_$vcenter.csv\"\n" + "```\n" + "\n" + "the script connects to a vcenter server of your choice (fill the $vcenter variable!) and then reads out all the vms. it then goes through each vm and gets the guest object of each VM. after that we simply put together our values into variables. \n" + "since dns names always differ from hostnames when dns is fqdn, I go ahead and count the dots (.) in the dns-name. if there are some, they will be cut away, otherwise it's fine. if the dns-hostname is $null it means that the VM is powered off or doesn't have the necessary tools installed. \n" + "this is one of my first powershell scripts, so I guess I could have made it work with a few less variables, but hey, it works.. 🙂", }, ], }, status: { corpus: 315, comments: 1, alsoLike: [ { ref: "posts/vmware-explore-las-vegas-hackathon-2025", score: "1.00", }, { ref: "posts/vmware-hackathon-2024-project", score: "1.00", }, { ref: "solutions/vmware/vmware-cloud-foundation/addon/business-operations", score: "0.60", }, ], search: "/en/search.json", },};console.log(JSON.stringify(page, null, 2));

# 93 lines · YAML · validated at build# 62 lines · JSON · validated at build# 106 lines · TOML · validated at build# 116 lines · XML · validated at build# 118 lines · Python · read back at build, equals the JSON record# 115 lines · PowerShell · read back at build, equals the JSON record# 128 lines · Go · read back at build, equals the JSON record# 113 lines · JavaScript · read back at build, equals the JSON record · served at /en/insights/powercli-find-differences-between-dns-name-and-vm-display-name.md

Scripting · 2014-12-09

Find differences between DNS-Name and VM Display-Name

My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client.

2014-12-09Date
Dario DörflingerAuthor
2Min read
Vendors VMware 0.98

This post is from 2014. It stays online because people still look for it, but it describes the products as they were then.

My boss asked me to create a report which shows all the VMs that have a difference in DNS-hostname and the displayname shown in the client. The reason is simple: our backup solution sometimes has troubles when those values differ. And in some rare occassion we cannot find the VM on which we should be doing support on because the client only knows the dns-name and we can only find VMs by displayname.
Update: this script is now published at GitHub.

Long story, short script:

$OutArray = @()

$vms = Get-VM
foreach ($vm in $vms)
{
$myobj = "" | Select "VM", "DNSname", "Status"
$guest = Get-VMGuest -VM $vm
$pat = "."
$vmname = $guest.VmName
$hostname = $guest.HostName
$myobj.VM = $vmname
$myobj.DNSname = $hostname
if ( $hostname -ne $null)
{
$pos = $hostname.IndexOf(".")
if ( $pos -ne "-1")
{
$hostname = $hostname.Substring(0, $pos)
}
if ( $hostname -ne $vmname )
{
Write-Host -ForegroundColor Red "---> The VM: $vm has different DNS and Display-Name!"
Write-Host -ForegroundColor Red "---->Hostname: " $hostname
Write-Host -ForegroundColor Red "---->VmName: "$vmname
$myobj.Status = "Not OK!"
}
Else
{
Write-Host -ForegroundColor Green "---> The VM: $vm has identical Names."
$myobj.Status = "OK!"
}
}
Else
{
Write-Host -ForegroundColor Yellow "---> The VM: $vm is not powered-on. Hostname cannot be found in this state!"
$myobj.Status = "N/A"
}
Clear-variable -Name hostname
Clear-variable -Name vmname
$OutArray += $myobj
}
$OutArray | Export-Csv "c:\tmp\name_vs_dns_$vcenter.csv"

the script connects to a vcenter server of your choice (fill the $vcenter variable!) and then reads out all the vms. it then goes through each vm and gets the guest object of each VM. after that we simply put together our values into variables.
since dns names always differ from hostnames when dns is fqdn, I go ahead and count the dots (.) in the dns-name. if there are some, they will be cut away, otherwise it’s fine. if the dns-hostname is $null it means that the VM is powered off or doesn’t have the necessary tools installed.
this is one of my first powershell scripts, so I guess I could have made it work with a few less variables, but hey, it works.. 🙂

Comments

1 comments from the previous blog. We no longer take new ones here.

chatski 2019-03-19

Thanks, helpful!

You might also like