-
-
Save mauroprojetos/de9593320192a72469ca13bc3c373f17 to your computer and use it in GitHub Desktop.
PowerShell: Get the IPv4 addresses of VMs running on a host
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Get the IPv4 addresses of the VMs where the VMNetworkAdapter status is OK | |
| # presuming a single VmNIC on the VM | |
| # I need to check and see if the following is always true | |
| # $_.IPAddresses[0] is the IPv4 address | |
| # $_.IPAddresses[1] is the IPv6 address | |
| Get-VMNetworkAdapter -VMName * | Where-Object {$_.Status -eq “Ok”} | ForEach-Object {Write-Host $_.VMName ", " $_.IPAddresses[0]} | |
| # Get the IPv4 addresses of the running VMs | |
| Get-VM | Where-Object {$_.State -eq “Running”} | Select -ExpandProperty NetworkAdapters | ForEach-Object {Write-Host $_.VMName ", " $_.IPAddresses[0]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment