Getting IP configurations of Virtual Machines with PowerShell and SCVMM

Every once in a while I find myself in an environment where no one has a clue which VM’s are part of a network, let’s say the DMZ.
Since this is mostly identified by IP address/range I create a script to provide me with a list of IP configurations by using the SCVMM cmdlets:

Get-VMMServer localhost | out-null
$VMs = Get-VM
Foreach-object ($VM in $VMs)
   if (($VM.ComputerName -ne $NULL) -AND ($VM.ComputerName -ne "*"))
      $IPS = [System.Net.DNS]::GetHostAddresses($VM.Name)
      trap [System.Exception] {"The following virtual machine is not registered in DNS:"; continue;}
      write-Host ""      
      write-Host "VM:   " $VM.Name
      write-Host "Name: " $VM.ComputerName
      Write-Host "IP:   " $IPS
      Write-Host ""   

As you may have noticed, this script uses DNS to resolve the IP address.

Now, with the new PowerShell cmdlets introduced with SCVMM 2012 life suddenly becomes much, much easier… especially for me since I´m a huge fan of one liners Emoticon met brede lach
With SCVMM 2012, use the following to get the same information:

Get-SCVirtualMachine –VMMServer localhost | Format-List -property Name, ComputerName, IPV4Address

Leave a Reply

Your email address will not be published. Required fields are marked *