I'm trying to split up an array of user objects retrieved via $users = Get-QADUser -searchroot 'domain.net/OU1/OU2/Users' into two arrays based on their 'AccountIsExpired'-property.
I can do $users = $users | where {!($_.AccountIsExpired)} but that only gives me one part of my users. However, this does filter out some user objects.
I build this code to split $users into two arrays ($include, $exclude):
[Object[]]$include = @();
[Object[]]$exclude = @();
foreach ($user in $users) {
if (!($_.AccountIsExpired)) {
$include += $user;
} else {
$exclude += $user;
}
}
$users = $include;
Apart from the creation of a second array, I don't see the difference between those two bits of code...