Created
October 24, 2018 08:07
-
-
Save vMarkusK/9fcd2bd3b6419597d6797da5cbb21b45 to your computer and use it in GitHub Desktop.
Find Duplicate VM IPs
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
Function GetArrayDupes { | |
param($array) | |
$hash = @{} | |
$array | %{ $hash[$_] = $hash[$_] + 1 } | |
$result = $hash.GetEnumerator() | ?{$_.value -gt 1} | %{$_.key} | |
Return $result | |
} | |
$VMs = Get-VM | |
$IPs = $VMs.Guest.IPAddress | |
$VMsDetected = @() | |
foreach ($IP in $(GetArrayDupes -array $IPs)) { | |
$VMsDetected += $VMs | where {$_.Guest.IPAddress -like $IP} | |
} | |
$VMsDetected | Select Name, @{N="IP";E={$_.Guest.IPAddress | where {$_ -notlike "fe80*"} | sort }} | Sort Name | Format-Table -Autosize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment