I need to write a PowerShell script that queries the Active Directory for the SID/GUID of certain objects and finds the least available SID/GUID within a range.
I want to take the approach of querying the AD at once and populating an array with all SIDs and then sorting this array in increasing order. Then I’ll initialize a variable with the lower limit of my SID range and compare with the array.
Now I have 2 questions:
-
How can I query the AD for all Objects and populate an array of SIDs from there?
-
How do I compare two SID values (they are in a very complex format)?
Thanks!
Using Quest module for Active Directory is pretty simple:
The you can find some match like this: