I am trying to get a list of properties of AD user objects. Most of the script works except the "where-object" filters are applied. I want to get all users who meet the following: LastLogonDate is more than 75 days ago (this works), enabled (this works) AND either of the following - account expires in the future or never expires. $when is defined properly.
I've tried a number of options and I typically get no output or one or the other in the output.
| Where-Object{($_.lastlogondate -le $When -AND $_.enabled -eq $True) -AND Where-Object($_.AccountExpirationDate -gt (Get-Date) -OR $_.AccountExpirationDate -eq 0)} |
I should see accounts with expiry dates in the future AND accounts that do not expire, but I'm having problems with the "This AND this AND (this OR this)"
Where-Objectlike that. [grin] you need to either pipe from one tot he next OR use a compound set of criteria in one W-O stage.Get-Datein the pipeline like that will slow things down - it gets called once per item. [grin] calc that value before you enter the pipeline.