ThinkPaper
asked on
GAL/Powershell: Traverse within an OU and set customattribute = OU
Experts -
Need some assistance hashing out this script. =)
We get a regular import of contacts from an external source. These mailcontacts are sorted by OU, and the entire GAL dump (OU and contacts) are controlled by the external source (they have a service account with us).
So what we get is a dump of contacts organized by OU in our AD structure - so the OU structure for this dump looks like:
boo.com
- External Contacts (root OU)
- Dairy
Head.Honcho@dairy.com
- Milk
John.Smith@milk.com
Carrie.Underwood@milk.com
Super.Man@cows.com
- Cheeses
Steve.Carrell@cheeses.com
- Hard Cheese
Whoopi.Goldberg@hardcheese .com
- Soft Cheese
John.Stamos@softcheese.com
Jeff.Goldblum@softcheese.c om
- Meats
john.hancock@meats.com
- Red Meat
bobby.flay@redmeat.com
jennifer.gray@superdome.co m
Contacts within the OUs do NOT always have the same email domain.
We need to make our own address lists to reflect the OU structure. What I was planning on doing was to make a powershell script to set the "customattribute1" field equal to their OU. We would then use the custom attribute field to create the appropriate address lists.
This Powershell command works by itself for 1 OU:
However, I want to automate this a little bit more. Instead of having to run the same commands 50 times for 50 OUs, I'd like to create a powershell script to:
1) Traverse through the "External Contacts"
2) In each OU
3) Look at each mailcontact
4) If customattribute1 is blank, set customattribute1 for each contact equal to the OU
5) Move to next contact/OU
I would think this should be relatively simple, but I am still not familiar enough with PowerShell to figure this out.
THANK YOU!! =)
Need some assistance hashing out this script. =)
We get a regular import of contacts from an external source. These mailcontacts are sorted by OU, and the entire GAL dump (OU and contacts) are controlled by the external source (they have a service account with us).
So what we get is a dump of contacts organized by OU in our AD structure - so the OU structure for this dump looks like:
boo.com
- External Contacts (root OU)
- Dairy
Head.Honcho@dairy.com
- Milk
John.Smith@milk.com
Carrie.Underwood@milk.com
Super.Man@cows.com
- Cheeses
Steve.Carrell@cheeses.com
- Hard Cheese
Whoopi.Goldberg@hardcheese
- Soft Cheese
John.Stamos@softcheese.com
Jeff.Goldblum@softcheese.c
- Meats
john.hancock@meats.com
- Red Meat
bobby.flay@redmeat.com
jennifer.gray@superdome.co
Contacts within the OUs do NOT always have the same email domain.
We need to make our own address lists to reflect the OU structure. What I was planning on doing was to make a powershell script to set the "customattribute1" field equal to their OU. We would then use the custom attribute field to create the appropriate address lists.
This Powershell command works by itself for 1 OU:
Get-Mailcontact -OrganizationalUnit "OU=Milk,OU=Dairy,OU=External Contacts,DC=boo,DC=com" -ResultSize Unlimited | Where {$_.CustomAttribute1 -eq "$null"} | Set-Mailcontact -CustomAttribute1 "milk"
However, I want to automate this a little bit more. Instead of having to run the same commands 50 times for 50 OUs, I'd like to create a powershell script to:
1) Traverse through the "External Contacts"
2) In each OU
3) Look at each mailcontact
4) If customattribute1 is blank, set customattribute1 for each contact equal to the OU
5) Move to next contact/OU
I would think this should be relatively simple, but I am still not familiar enough with PowerShell to figure this out.
THANK YOU!! =)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have tested it in my lab and it's working for me.. It will set the CustomAttribute1 to the OU name where the contact object resides in. Is that what you looking for?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
% is the alias for ForEach.. I am not sure why my script didn't work.. functionally both your script and my script does the same thing.. Any way glad you got it worked.. :-)
ASKER
Solution worked, but needed a little tweaking. Thank you!
ASKER
I"ll keep playing with the script..