title: Get DNS server IP addresses associated with Azure VMs
body: <p>I have a list of servers which I need to get the DNS server IP settings from, these servers are in Azure. I thought this would be simple to get the nic and query the properties of the nic to isolate the dns ip assigned to it.</p>
  
  <p>I used:</p>
  
  <pre><code>$rg = main-rg
  Get-AzureRmNetworkInterface -ResourceGroupName $rg | ForEach { $Interface = $_.Name; $IPs = $_ |`
       Get-AzureRmNetworkInterfaceIpConfig | Select PrivateIPAddress; Write-Host $Interface $IPs.PrivateIPAddress }  
  </code></pre>
  
  <p>To get <code>privateIPaddress</code>, but this is for a single resource group. Would I need to put this into a <code>foreach</code> loop? </p>
  
  <p>Maybe like:</p>
  
  <pre><code>    $rg = get-content c:\temp\list-of-res-grps.txt
  foreach ($rgs in $rg)
  {
      Get-AzureRmNetworkInterface -ResourceGroupName $rg | ForEach { $Interface = $_.Name; $IPs = $_ |`
           Get-AzureRmNetworkInterfaceIpConfig | Select PrivateIPAddress; Write-Host $Interface $IPs.PrivateIPAddress }  
  }
  </code></pre>
  
  <p>To get the name of the nics I used, which also gives hostname. </p>
  
  <pre><code>get-azurermvm | out-file c:\temp\servers.txt
  </code></pre>
  
  <p>Is there a way to query the nic for the dns server ip address? Or do I need to be digging deeper into the <code>Get-AzureRmNetworkInterfaceIpConfig</code> cmdlet?</p>
  
  <p>Hope I haven't missed anything obvious.</p>
  
  <p>Thanks in advance :)</p>