I am trying to get a list of UIDs (NIS attribute). The problem is that UIDs are not in order. I would like to define a range and check if an account exist with that UID and if it does then get me the last UID in range that was used. I have the following code working but it takes a lot of time to loop through the range (for this example, the range is very small). I would like to find out if there is any alternative way to accomplish the same with better performance.
[int32[]] $array= 50000..100000
$initArray = @()
foreach ($arr in $array){
$acct = (Get-ADUser -Filter (uidnumber -eq $arr) -Properties uidNumber) | select name, uidnumber
$initArray += $acct.uidnumber
}
$initArray | Select -Last 1
This gets me the last used uid but if the range is, let's say, from 300000 to 900000 then the foreach loop is going to take a lot of time in getting the last UID. Any help would be appreciated.
PSVersion: 2.0
while ($found -eq $nul)
and assign a value to $found when you have your first hit?