Created
March 24, 2018 11:52
-
-
Save gowatana/450bd1476d1d75b31d257240373bbc5d to your computer and use it in GitHub Desktop.
This file contains 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
# 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