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.

Revisions

  1. @kdaniel32 kdaniel32 revised this gist Dec 28, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Get-VmIPv4.ps1
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    # 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]}
  2. @kdaniel32 kdaniel32 revised this gist Dec 28, 2017. No changes.
  3. @kdaniel32 kdaniel32 created this gist Dec 27, 2017.
    7 changes: 7 additions & 0 deletions Get-VmIPv4.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    # Get the IPv4 addresses of the VMs where the VMNetworkAdapter status is OK
    # $_.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]}