Did you know that you can use Where-Object to split a collection into two arrays? Like, if you had an array containing the numbers 1 to 10, you could split it into one array of even numbers, and another array of odd numbers? It’s pretty cool. Thanks Herb Meyerowitz for this tip!
If you’re just getting started in PowerShell, it’s possible that you haven’t bumped into this specific issue yet. Perhaps you’ve got a variable $users and you’re assigning it a value like this.
PS> $users = Get-ADUser -Filter "samaccountname -like '*thmsrynr'"
This will get all the users in your Active Directory whose username ends with “thmsrynr”.
Great! Now how many users got returned? We can check the Count property to find out.