I'm trying to edit a script that does a few things: it compares two arrays and removes known unavailable strings from the first array it polls AD and prints all the strings that are not found in AD.
The problem is, I don't want to initially use an array, I want to use a csv. Well, the other problem is I'm feeling my way around with Powershell. I've edited this so I'm not using real numbers, but here's what I've got. Please do help.
# Find free numbers in AD
$numberRanges = @(
@(6667778001,6667778999),
@(6667776001,6667777999)
)
[System.Collections.ArrayList]$knownUnavailable = 6667778203,6667777212,6667777213
[System.Collections.ArrayList]$knownUnavailableU64 = @()
foreach ( $knownUnavailableItem in $knownUnavailable ) {
$knownUnavailableU64 += [UInt64]$knownUnavailableItem
}
$strFilter = '(&(objectCategory=User)(telephonenumber=*-*-*))'
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$colResults = $objSearcher.FindAll()
$aDNumbers = @()
foreach ($objResult in $colResults) {
$objItem = $objResult.Properties
$aDNumbers+=[UInt64]($objItem.telephonenumber.Replace("-",""))
}
$availableNumbers = @()
foreach ($numberSet in $numberRanges) {
$lowerBound=[UInt64]$numberSet[0]
$upperBound=[UInt64]$numberSet[1]
for($i = $lowerBound; $i -le $upperBound; $i++) {
if ( !( $aDNumbers.Contains($i)) -and !( $knownUnavailableU64.Contains($i) )
) {
$availableNumbers+=$i
}
}
[array]::sort($availableNumbers)
}
$availableNumbers | % { "{0:##########}" -f $_ }
write-host "Press any key to close..."
[void][System.Console]::ReadKey($true)
Ideally I'd use this type of csv and skip the arrays altogether:
knownDID,usable
6667778001,
6667778002,
6667778003,FALSE
6667778004,
6667778005,
Thanks for reading!