April 03, 2023

Use PowerCLI to Sync VM addresses to Google Cloud DNS

Use PowerShell modules from VMware and Google Cloud to automatically sync the IP addresses of virtual machines running on Google Cloud VMware Engine with Google Cloud DNS.

Google Cloud DNS is an easy-to-use, fully managed service that provides reliable, low-latency name resolution for your cloud operations. And because it’s a cloud service, there are various options administrators can leverage to automate management tasks, including creating and updating forward and reverse resource records.

If you are running your VMware workloads on Google Cloud VMware Engine, then you might be interested in the tight integration that Cloud DNS can offer. Let’s look into one approach that can be used to automate the synchronization of DNS records for virtual machines running on a VMware private cloud.

Most VMware administrators are familiar with VMware PowerCLI and rely on the versatile tool for a broad range of operational tasks and automation. But one thing you may not know is that Google Cloud Tools for PowerShell works similarly for a handful of popular Google Cloud services – including Cloud DNS. You can combine these two PowerShell modules to query a set of VMs running on Google Cloud VMware Engine and create forward and reverse DNS records on Cloud DNS.

Getting Virtual Machine IP Information

There are a couple of different approaches you can use to obtain the guest IP address and hostname from a VM running on VMware vSphere. One way is to pipe the output of Get-VM to Get-VMGuest and select the attributes you like. Another, more streamlined method is to look at the .Guest property from a VM:

> Get-VM winsvr-ad1 | Get-VMGuest | select HostName, IPAddress

> (Get-VM winsvr-ad1).Guest.HostName

Note that depending on how a guest OS is configured, VMware Tools may return just the base hostname and not a FQDN, which is why you may sometimes see just a short hostname displayed in vCenter when looking at “DNS Name” for a particular VM, as seen in the image below.  But that’s outside the scope of this post. 


Add Records to Google Cloud DNS

Once you have the guest IP addresses and hostnames from VMs running in the private cloud, you can use Cloud Tools for PowerShell to create resource records on Cloud DNS. Assuming the managed DNS domains already exist, adding a record involves two steps: First create one or more records with the New-GcdResourceRecordSet command and then use the Add-GcdChange command to apply those records to the zone.

Review the full documentation to see how the commands work together.

Example PowerCLI Script to Automate Cloud DNS Sync

On GitHub I have a repository of sample scripts that you can use as a starting point for your own automation efforts. The module GcveDnsSync.psm1 shows how to tie the two concepts discussed above into a smooth workflow that adds, updates, or removes forward and reverse records to Cloud DNS. It’s designed to operate on the output of Get-VM, so it’s easy to work with a subset of the inventory by providing appropriate wildcard filters.

Here is an example of how to use the command:

Import-Module ./GcveAuthentication.psm1
Import-Module ./GcveDnsSync.psm1
Connect-VIServerGcve -PrivateCloud orange

Get-VM web* | Sync-DnsRecordsFromVm -DomainName multicloud.internal `
-ReverseDomainName 88.10.in-addr.arpa

To authenticate, you will need to have gcloud CLI properly configured.  See the Google Cloud Tools for PowerShell Quickstart for details.

See it in Action



As you begin your move to the public cloud and start adopting more and more cloud services, it’s good to know that existing skills and familiar concepts will carry over with you. Google Cloud VMware Engine is built upon the proven VMware SDDC stack with vSphere, vSAN, and NSX. You can continue running your workloads on a consistent platform without converting or re-architecting, and you can take advantage of services offered in the public cloud to enhance your infrastructure and operations.

Filter Tags

Automation Google Services PowerCLI Google Cloud VMware Engine Blog