'Where-Object -and -or issues
I have an error (or situation) that is driving me crazy. I have a script in which I use a piped where-object to select certain accounts of users.
$ExpirationDate = Get-ADUser -Filter {(PasswordNeverExpires -eq $false) -and (Enabled -eq $true)} -Properties "msDS-UserPasswordExpiryTimeComputed" | Where-Object {($_.'msDS-UserPasswordExpiryTimeComputed' -lt $MaxDate) -and ($_.DistinguishedName -notlike "*,OU=Service Accounts,*" -or $_.DistinguishedName -notlike "*,OU=Ressources,*")}enter code here
I have used something similar in other scripts and worked perfectly. However, in this particular case, if I run it till the "-and", I get 31 users. If then I add the first part of the "-Or", they go down to 26 but, if I add the second part, to reduce even more the number of users taken into account (the two -or are to filter certain OUs), I got again 31 users.
I have tried () to separate the -or, not use any (), and anything that I could imagine to get the real number, but I wasn't able to make it work.
Any suggestions?
Best regards
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
