list all users who are carted from past 1 year. and check if they exists in a few DL's

This is not giving any results.
can you help find fix this..

I am trying to list all users who are carted from past 1 year. and check if they exists in a few DL's

Get-ADUser -Filter * -SearchBase "MY OU path" -SearchScope Subtree -Properties * | ?{$_.Created -ge ((Get-Date).AddDays(-365)).Date -and ($_.MemberOf -contains "DL1" -or $_.MemberOf -contains "DL2")} | select -Property name, LastLogonDate, PasswordLastSet,UserPrincipalName,EmailAddress

Open in new window

porambokuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zvitamConsultantCommented:
Try to debug one part at time.

Start with:

Get-ADUser -Filter * -SearchBase "MY OU path" -SearchScope Subtree -Properties *

Do you get anything? if not, check you conditon

If you get something, then add the next condition

Get-ADUser -Filter * -SearchBase "MY OU path" -SearchScope Subtree -Properties * | ?{$_.Created -ge ((Get-Date).AddDays(-365)).Date

and so on...
0
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
This should do the needful.

On my phone so can't test for syntax errors:

#####

$DebugPreference = "Continue"

$AYearAgo = ((Get-Date).AddDays(-365)).Date

#Debug show the date a year ago
Write-Output
$AYearAgo | Write-Debug

$UsersAndGroups = Get-ADUser -Filter {whenCreated -ge $AYearAgo} -Properties whenCreated, MemberOf

#Debug show shortlist of users and groups
Write-Output
$UsersAndGroups | write-debug

#Output long list of users to groups:
Foreach ($User in $UsersAndGroups) {
Write-Output
Foreach ($Group in $($User| Select -ExpandProperty memberof) ) {
Write-Output "$User ---> $Group"
}

}

#####

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Ahh, I see you had a list of groups.  Okay we can modify to accomodate that and pull the matches only.  Almost finished with commute though, so I'll have to do that later, or somone else can expand upon this.
0
dsuyemotoCommented:
Don't use
-contains
since you're trying a string match, instead use
-like "*DL1*"
0
porambokuAuthor Commented:
direcited
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.