I need to pull a list of accounts from a single OU that have 2 specific values in 2 attributes, these accounts also need to have not reset their passwords in a number of days.
I can run part of my script and get the accounts without password reset in the given number of days, but as soon as I add a condition looking for either of the attribute values it returns 0 results, even though I know there are thousands of them
The code I am trying is
$PasswordAge = 30 $time = (Get-Date).Adddays(-($PasswordAge)) Get-ADUser -ResultpageSize 20000 -Filter {pwdLastSet -lt $time} -SearchBase "ou=MYOU,dc=domain,dc=com" | Where-Object {$_.customattribute -contains 'Value'} | Where-Object {$_.memberof -contains 'CN=Group Name,OU=Security Groups (Mail Enabled),DC=domain,DC=com'} Select-Object sAMAccountName | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 | Set-Content -Path "c:\users\test.csv"
So this should give me all accounts in MYOU with a password reset date of 30 days or more in the past with the given values in customattribute and memberof. The results should be saved to a csv on my C drive with the column headercremoved and only the saMAccountName attribute should be listed.
If I run just
$PasswordAge = 30 $time = (Get-Date).Adddays(-($PasswordAge)) Get-ADUser -ResultpageSize 20000 -Filter {pwdLastSet -lt $time} -SearchBase "ou=MYOU,dc=domain,dc=com" | Select-Object sAMAccountName |
I get all the sAMAccountName values for users in the OU with no password reset in 30 days or more scrolling down the screen, if I add the code to export to csv I get the same results saved to the csv file
What am I doing wrong?