Help with Powershell ad query (driving me crazy )

I need to create a CSV list from active directory as follows:
Name, Email Address, Display Name, Group : memberships separated by ";" , Is External User (Boolean)
the constrictions are :
1. we are creating a list for users in RED group.
2. we we need to also note group membership in our list , for users who belong to any group like *admin*
3. we need to add a "False" at he end of each line in the  csv  file (as none of ad users are external.

so far i have this;
Get-ADGroupmember -Identity RED-Group |Where-Object { $_.objectClass -eq 'user' } |Get-ADUser -Properties * ||Select-Object -Property Name, Emailaddress, CN, @{name='MemberOf';expression={ ($_.MemberOf | ForEach { ($_ -split ',')[0] -replace 'CN=',''}) -join ';'}} |ConvertTo-Csv -NoTypeInformation |Out-File redusers.csv

Open in new window



i need to filter the $_.MemberOf property with something like  "where { $_.group -like admin }"  as i dont want to list all groups membership -  but not getting that right.

Any suggestions?
Thanks
Me.
PleaseAnswerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

yo_beeDirector of Information TechnologyCommented:
Try this

Get-ADGroupmember -Identity Red-Group |Where-Object { $_.objectClass -eq 'user' } |  Get-ADUser -Properties * | Select-Object -Property Name, Emailaddress, CN, @{name='MemberOf';expression={ ($_.MemberOf | Where-Object {$_ -notlike '*Admin*'} |ForEach { ($_ -split ',')[0] -replace 'CN=',''}) -join ';'}} | Export-Csv redusers.csv -NoTypeInformation 

Open in new window


I removed the covert command and replaced it with Export-CSV as well as added the Where-Objet to filter out groups with the name Admin in it.

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
PleaseAnswerAuthor Commented:
cool,  :) that works .
now how do i add a check to each users that if he is in the domain i get a "false" at the end of each line of the csv?
yo_beeDirector of Information TechnologyCommented:
Do you have an example of an external -properties Results?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

PleaseAnswerAuthor Commented:
nop, i don't they do not exist in AD , i just need the CSV to to have another column heading "NotIn-AD" and for all the users to be 'False' for that line  - since they are not external users...
PleaseAnswerAuthor Commented:
actually got it , just added "@{name='IsExternal';expression={'False'}}"

That works
Thanks!!!!
PleaseAnswerAuthor Commented:
Thanks Yo_Bee !!
yo_beeDirector of Information TechnologyCommented:
No Problem
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.