2
votes

I am wondering if there is a way to filter this:

Search-ADAccount -AccountInactive -DateTime ((get-date).adddays(-90)) -Usersonly

By adding pipeline:

| where-object {($_.samAccountName -notlike "*_ua1") -and ($ _.memberOf -like "*UserAdminL1 *")}

It seems like it freezes and do nothing.

Maybe there is a correct way to do this ?

1

1 Answers

0
votes

Search-ADAccount does not return group memberships. If you want to filter on that you could first pipe into Get-AdUser to get the memberOf property. You also are missing the Where-Object portion of your filter and the $ _.memberOf should be $_.memberOf. Compile errors would have been trying to correct that for you so you might just have a copy paste issue with your question.

Search-ADAccount -AccountInactive -DateTime ((get-date).adddays(-90)) -Usersonly | 
    Get-Aduser -Properties memberof | 
    Where-Object {($_.samAccountName -notlike "*_ua1") -and ($_.memberOf -like "*UserAdminL1 *")}