Skip to content

Instantly share code, notes, and snippets.

@vMarkusK
Created October 24, 2018 08:07
Show Gist options
  • Save vMarkusK/9fcd2bd3b6419597d6797da5cbb21b45 to your computer and use it in GitHub Desktop.
Save vMarkusK/9fcd2bd3b6419597d6797da5cbb21b45 to your computer and use it in GitHub Desktop.
Find Duplicate VM IPs
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