I am creating a script that lists all inactive computer accounts. I would like to exclude several systems from the results.
I have a text file containing all the systems that need to be excluded (one system name per line). All elements are stored in the object with the property name "name". So $ excluded will contain:
name ---- system1 system2
To list all inactive systems, I use the Search-ADAccount cmdlet:
$InactiveComputers = Search-ADAccount -AccountInactive -TimeSpan 90 -ComputersOnly | Where {$_.Enabled -eq $true}
Of course, I can loop all the results 1 on 1, but is there an easy way to exclude systems directly from the results? I have a feeling that this is possible with select-object or where-object, but I cannot figure out how to compare the results with objects.
source share