For official work, I wanted to print out a list of all the VMs and their associated network/portgroups and IP details. since I am dealing with thousands of VMs this was a difficult task to perform manually. I was searching and trying to write a script to get the expected result. Finally, To get this info I ran the following command:
Get-DataCenter DataCenterName | Get-VM | Get-NetworkAdapter | Select-Object @{N="VM";E={$_.Parent.Name}},@{N="NIC";E={$_.Name}},@{N="Network";E={$_.NetworkName}}
But what I expected it to run get the output based on the cluster. therefore modified the command as follows
Get-Cluster ClusterName | Get-VM | Get-NetworkAdapter | Select-Object @{N="VM";E={$_.Parent.Name}},@{N="NIC";E={$_.Name}},@{N="Network";E={$_.NetworkName}}
This gave me a nice output.
But that was not enough, the requirement was to retrieve the IP addresses. For this, I used the below script to take the result.
Get-Cluster ClusterName | Get-VM | Select-Object -Property Name,@Name='IPAddress';Expression={($_ | Get-VMGuest).IPAddress}},@Name='NetworkName';Expression={($_ | Get-NetworkAdapter).NetworkName}}
Added the following at the end of the script to get the output to a CSV file.
| Export-Csv c:\geethvmlist.csv
.
I was excited to uncover this great site. I need to to thank you for your time for this particularly wonderful read!! I definitely enjoyed every part of it and I have you book marked to check out new stuff in your web site.