Skip to content

Instantly share code, notes, and snippets.

@gowatana
Created March 24, 2018 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gowatana/450bd1476d1d75b31d257240373bbc5d to your computer and use it in GitHub Desktop.
Save gowatana/450bd1476d1d75b31d257240373bbc5d to your computer and use it in GitHub Desktop.
# IP -> vNIC Report Scriopt.
#
# Usage:
# PowerCLI> .\get_guest_ip.ps1 -VMs vm01,vm02
# PowerCLI> .\get_guest_ip.ps1 -VMs vm01 -IPv4Only
# PowerCLI> .\get_guest_ip.ps1 -VMs vm01 -IPv4Only | ft -AutoSize
Param(
[Array]$VMs,
[Switch]$IPv4Only = $false
)
$guests = Get-VM -Name $VMs | Get-VMGuest
$vnic_ip_info = $guests | % {
$guest = $_
$vm_name = $guest.VM.Name
$power_state = $guest.VM.PowerState
$tools_status = $guest.ExtensionData.ToolsStatus
$guest.ExtensionData.Net | % {
$vnic = $_
$key = $vnic.DeviceConfigId
$mac = $vnic.MacAddress
$network = $vnic.Network
$connected = $vnic.Connected
$vnic.IpConfig | select -ExpandProperty IpAddress | select `
@{N="VM";E={$vm_name}},
@{N="PowerState";E={$power_state}},
@{N="ToolsState";E={$tools_status}},
@{N="key";E={$key}},
@{N="Mac";E={$mac}},
@{N="Portgroup";E={$network}},
@{N="Connected";E={$connected}},
IpAddress,
PrefixLength
}
}
if($IPv4Only -eq $false){
$vnic_ip_info
}else{
$vnic_ip_info | where {$_.IpAddress -match "\d+\.\d+\.\d+\.\d+"}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment