wdurrett
asked on
Script for Contact Information in AD
Hi Experts.
I have one OU with about 40 child OUs. In each of these live mail-enabled contacts. I need a script that will recursively go through the OUs and generate the following in CSV format:
Name of Contact
Email Address
Title
Office
Group Membership (some contact may be members of up to 5 groups)
Can anyone help me here? The Group Membership part is the tricky one for me.
Thanks in advance!
I have one OU with about 40 child OUs. In each of these live mail-enabled contacts. I need a script that will recursively go through the OUs and generate the following in CSV format:
Name of Contact
Email Address
Title
Office
Group Membership (some contact may be members of up to 5 groups)
Can anyone help me here? The Group Membership part is the tricky one for me.
Thanks in advance!
ASKER
Hi Rob. Nice to see you agian. :)
I recived the following error:
Missing '(' after 'if' in if statement.
chapter_info.ps1:17 char:4
+ If <<<< Trim(strOU) <> "" Then
+ CategoryInfo : ParserError: (OpenParenToken:TokenId) [], ParseException
+ FullyQualifiedErrorId : MissingEndParenthesisInIfS tatement
I recived the following error:
Missing '(' after 'if' in if statement.
chapter_info.ps1:17 char:4
+ If <<<< Trim(strOU) <> "" Then
+ CategoryInfo : ParserError: (OpenParenToken:TokenId) [], ParseException
+ FullyQualifiedErrorId : MissingEndParenthesisInIfS
Hi, sorry, this is not PowerShell. It's VBS. Save it as a VBS and run it.
Regarsd,
Rob.
Regarsd,
Rob.
ASKER
Sorry, my bad. However, I got this new error:
c:>chapter_info.vbs(21, 1) Provider: Table does not exist.
c:>chapter_info.vbs(21, 1) Provider: Table does not exist.
Double check your OU path. It needs to be listed in reverse order, not including the DC parts. So, if you need to enumerate:
domain.com/Sites/MainOffic e/Users
Then use
strOU = "OU=Users,OU=MainOffice,OU =Sites,"
Regards,
Rob.
domain.com/Sites/MainOffic
Then use
strOU = "OU=Users,OU=MainOffice,OU
Regards,
Rob.
ASKER
My bad agian. I was missing an "s" at the end of my OU.
But now I come back with yet another error:
c:\chapter_info.vbs(32, 7) Microsoft VBScript runtime error: Type mismatch
But now I come back with yet another error:
c:\chapter_info.vbs(32, 7) Microsoft VBScript runtime error: Type mismatch
Oh! This time it's my bad.....change this:
For Each strGroup In objUser.MemberOf
objOutput.WriteLine ",""" & objUser.MemberOf & """"
Next
to this
For Each strGroup In objUser.MemberOf
objOutput.WriteLine ",""" & strGroup & """"
Next
Regards,
Rob.
For Each strGroup In objUser.MemberOf
objOutput.WriteLine ",""" & objUser.MemberOf & """"
Next
to this
For Each strGroup In objUser.MemberOf
objOutput.WriteLine ",""" & strGroup & """"
Next
Regards,
Rob.
ASKER
OK, that time I did get some output. However, there are some issues.
1) Iam seeing CN= in front of all the names. I can deal with this if it has to be this way, but my hope is to pass this along to a non-technical end user for her to run. That will freak her out.
2) The group names show as "CN=Seattle Core Committee,OU=Seattle,OU=Un ited States,OU=Chapters,OU=Inte rnet Contacts,DC=mydoman,DC=org " Once again, I woudl like it just say "Seattle Core Committee."
Thanks in advance for your help.
1) Iam seeing CN= in front of all the names. I can deal with this if it has to be this way, but my hope is to pass this along to a non-technical end user for her to run. That will freak her out.
2) The group names show as "CN=Seattle Core Committee,OU=Seattle,OU=Un
Thanks in advance for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
One last request:
If a contact is not a member of any group, can it return "None"? I am seeing some errors in the output followng a contact that has no group membership.
Thanks dude. you are awesome.
If a contact is not a member of any group, can it return "None"? I am seeing some errors in the output followng a contact that has no group membership.
Thanks dude. you are awesome.
Sure, just change
If TypeName(objUser.MemberOf) = "Empty" Then
objOutput.WriteLine ","""
to
If TypeName(objUser.MemberOf) = "Empty" Then
objOutput.WriteLine ",None"""
Regards,
Rob.
If TypeName(objUser.MemberOf)
objOutput.WriteLine ","""
to
If TypeName(objUser.MemberOf)
objOutput.WriteLine ",None"""
Regards,
Rob.
ASKER
Yes, I just did that before you posted it.
The issue is that for any contact not in a group, the next contact is on the same line. It is like I need to add a line return in the script for those few contacts.
The issue is that for any contact not in a group, the next contact is on the same line. It is like I need to add a line return in the script for those few contacts.
ASKER
Got it. I was missing a quote.
Thanks again.
Thanks again.
No problem. Thanks for the grade.
Regards,
Rob.
Regards,
Rob.
Regards,
Rob.
Open in new window