Skip to content

Instantly share code, notes, and snippets.

@mauroprojetos
Forked from kdaniel32/Get-VmIPv4.ps1
Created June 15, 2021 21:56
Show Gist options
  • Select an option

  • Save mauroprojetos/de9593320192a72469ca13bc3c373f17 to your computer and use it in GitHub Desktop.

Select an option

Save mauroprojetos/de9593320192a72469ca13bc3c373f17 to your computer and use it in GitHub Desktop.
PowerShell: Get the IPv4 addresses of VMs running on a host
# 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