|
<#Hi Guys Sharing with you all a script which i made to Find List of Used /Unused IP's in an IP Range
X.X.X. [First 3 Octet's of IP range, Example [(192.168.32.),(10.134.4.),(10.134.8.)]
A..AA [ First and last octet of IPRange [(1..254),(120..254)] inbetween which the IP's need to be found ]#>
A..AA | ForEach {
if (-not (test-connection -Count 1 -comp "X.X.X.$_" -quiet) -and (arp -a X.X.X.$_ -match "No ARP Entries Found."))
{ Write-Host "X.X.X.$_ is Free" -fore green
$info = @{
'IP_Address'="X.X.X.$_";
'Availability'="Unused";
}
$obj = New-Object -TypeName PSObject -Property $info
$array+=$obj
}
else {Write-Host "X.X.X.$_ is Used" -fore red
$info = @{
'IP_Address'="X.X.X.$_";
'Availability'="Used";
}
$obj = New-Object -TypeName PSObject -Property $info
$array+=$obj
}
}
Example :- Below script can be run to find list of Used / Unused IP's for ISCSI IP's
1..254 | ForEach {
if (-not (test-connection -Count 1 -comp "192.168.32.$_" -quiet) -and (arp -a 192.168.32.$_ -match "No ARP Entries Found."))
{ Write-Host "192.168.32.$_ is Free" -fore green
$info = @{
'IP_Address'="192.168.32.$_";
'Availability'="Unused";
}
$obj = New-Object -TypeName PSObject -Property $info
$array+=$obj
}
else {Write-Host "192.168.32.$_ is Used" -fore red
$info = @{
'IP_Address'="192.168.32.$_";
'Availability'="Used";
}
$obj = New-Object -TypeName PSObject -Property $info
$array+=$obj
}
}
|
hi, i have a question, how i get the unused ip result in .txt file?, and it´s possible to modify the code to first ip unused found stop the foreach?
thanks