PowerShell

I am working on PowerShell to get members of security group and export to CSV with AD attributes like name, email, department, employeID, title    
The PS below just gets the name and leaves the other fields.

Get-ADGroupMember -Identity "Domain" | Select-Object -properties name,mail,tittle,department,office |Export-csv C:\temp\Members.csv
Debrata 1Asked:
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.

Travis MartinezStorage EngineerCommented:
I believe you need to pipe the command to "get-aduser" and select the properties from there.  I used the following to test with:

Get-ADGroupMember -identity "Domain Users" | get-aduser -Filter * -properties Displayname, emailaddress, title, department, office | select displayname, emailaddress, title, department, office

Open in new window


Obviously the "Domain Users" would be replaced with "MCP-BCAST-PARKS" and add the export-csv to the end.
0
Debrata 1Author Commented:
Get-ADUser : Cannot find an object with identity: 'John, Smith"

I am getting the above error. I think the Get-ADGroupMember does not get the aduser ,rather it gets the first name and last name that's why we can not use Get-ADUser
0
Travis MartinezStorage EngineerCommented:
You're right, I broke the command before it finished completely but I was able to get the information you were looking for.  I'll work on it.
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

ITguy565Commented:
Try this
Get-ADGroupMember -Identity "domain users" |Get-ADUser -property Displayname, emailaddress, title, department, office | select displayname, emailaddress, title, department, office

Open in new window

1
Travis MartinezStorage EngineerCommented:
What ITguy565 put down worked for me.
0
Debrata 1Author Commented:
Same error, I don't think we can use Get-ADUser

Get-ADUser : Cannot find an object with identity: 'John, Smith"
0
ITguy565Commented:
Can you paste a screenshot of what you are getting when executing my code?
0
ITguy565Commented:
I just tested it and it is working at least here.. are you running admin powershell prompt?

I am also assuming that you are using

import-module activedirectory
0
ITguy565Commented:
Try this

Get-ADGroupMember -Identity "domain users" -EA SilentlyContinue |Get-ADUser -property Displayname, emailaddress, title, department, office | select displayname, emailaddress, title, department, office

Open in new window

0
ITguy565Commented:
@ALif Mehari

Did it work for you?
0
Debrata 1Author Commented:
Apologies, It's working now. I just made a mistake of the CSV path that i am looking at and the error is for some of the users not for all.
0
ITguy565Commented:
This should give you your export as well.

Get-ADGroupMember -Identity "domain users" -EA SilentlyContinue |Get-ADUser -property Displayname, emailaddress, title, department, office | select displayname, emailaddress, title, department, office |Export-csv C:\temp\Members.csv

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
Travis MartinezStorage EngineerCommented:
ITguy565 Had the correct command and output
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.