How to set with powershell the same Custom Attribute 1 to all recipient in my organisation?
Hi, I'm trying with the use of Get-Mailbox, Get-DistributionList and Get-MailContact to set the same customattribuet1 for all my organization's recipients. As i'm new in Powershell script and in general in programming, i'm kindly asking for some help, as i think the script could be optimized to run in a more smart way. I would like to set the 'customattribute1' a certain value, identical to all recipients, and it should only be applied to recipient that don't have it, with some kind of trigger on the Extention Attribute 1. Therefore, i'm wondering how i could interrogate all recipient in a OU, then apply the custom attribute to the ones that doesn't have it yet without taking too much power from my server? Some help would be very appreciated. Thank you in advane
March 3rd, 2010 9:21pm

Something like:get-mailbox -organizationalunit <OU name> -filter {customattribute1 -eq ""} | set-mailbox -customattribute1 = "<value>"
Free Windows Admin Tool Kit Click here and download it now
March 3rd, 2010 9:33pm

Hi mjolinor, Thank you for your answer. The filter will help the script in only processing mailbox where the CA1 is not set. I also want to process the same way all recipients (mailbox, DistributionList and MailContact). Do i have to put that command three times with the correct Get-string command? or is it possible to process every recipient in one piped command?
March 3rd, 2010 9:42pm

You can get them all in one command using get-recipient, but there is not a corresponding set-recipient command you can use to do the update, so I think you're stick with 3 commands. If this means entering 3 commands repeatedly to process multiple OUs I can show you how to do that without having to type in the commands over and over again for each OU.
Free Windows Admin Tool Kit Click here and download it now
March 3rd, 2010 9:46pm

Hi, Try this script get-Recipient -filter{CustomAttribute1 -eq $null }| foreach{ if($_.RecipientType -eq "UserMailbox") { Set-Mailbox $_.Identity -CustomAttribute1 "CS1" } if($_.RecipientType -eq "MailUniversalDistributionGroup") { Set-DistributionGroup $_.Identity -CustomAttribute1 "CS1" } if($_.RecipientType -eq "MailContact") { Set-MailContact $_.Identity -CustomAttribute1 "CS1" } } Save this script in a file with extension .ps1 e.g. "MyScript.ps1"and put it in "Scripts directory of Exchange Installation Folder which is normally "C:\Program Files\Microsoft\Exchange Server\Scripts". Also replace "CS1" with whatever u want to put there. Now just type the name of .ps1 file in EMS like "MyScript.ps1" and press enter. Regards, Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
March 3rd, 2010 10:18pm

in facts, my script is: Get-Mailbox -OrganizationalUnit 'hmcBO.corp -resultsize unlimited | set-mailbox -customattribute1 'mail.hmc.lu' Get-DistributionList -OrganizationalUnit 'hmcBO.corp -resultsize unlimited | set-Distributionlist -customattribute1 'mail.hmc.lu' Get-MailContact -OrganizationalUnit 'hmcBO.corp -resultsize unlimited | set-MailContact-customattribute1 'mail.hmc.lu' Do you think this script may be better written? I've also tried your suggestion with -filter string, but Active Directory don't seems to be able to process the filter string. Any idea?
Free Windows Admin Tool Kit Click here and download it now
March 3rd, 2010 10:21pm

Not sure why it doesn't like that filter. Where-object filtering seems to work OK.Get-Mailbox -OrganizationalUnit 'hmcBO.corp -resultsize unlimited |? {$_.customattribute1 -eq ""} | set-mailbox -customattribute1 'mail.hmc.lu'Get-DistributionList -OrganizationalUnit 'hmcBO.corp -resultsize unlimited |? {$_.customattribute1 -eq ""} | set-Distributionlist -customattribute1 'mail.hmc.lu'Get-MailContact -OrganizationalUnit 'hmcBO.corp -resultsize unlimited |? {$_.customattribute1 -eq ""} | set-MailContact-customattribute1 'mail.hmc.lu'
March 3rd, 2010 10:36pm

Looks like you're missing the closing quotes on your OU names, also.Get-Mailbox -OrganizationalUnit 'hmcBO.corp' -resultsize unlimited |? {$_.customattribute1 -eq ""} | set-mailbox -customattribute1 'mail.hmc.lu'Get-DistributionList -OrganizationalUnit 'hmcBO.corp' -resultsize unlimited |? {$_.customattribute1 -eq ""} | set-Distributionlist -customattribute1 'mail.hmc.lu'Get-MailContact -OrganizationalUnit 'hmcBO.corp' -resultsize unlimited |? {$_.customattribute1 -eq ""} | set-MailContact-customattribute1 'mail.hmc.lu'
Free Windows Admin Tool Kit Click here and download it now
March 3rd, 2010 10:38pm

in facts, my script is: Get-Mailbox -OrganizationalUnit 'hmcBO.corp -resultsize unlimited | set-mailbox -customattribute1 'mail.hmc.lu' Get-DistributionList -OrganizationalUnit 'hmcBO.corp -resultsize unlimited | set-Distributionlist -customattribute1 'mail.hmc.lu' Get-MailContact -OrganizationalUnit 'hmcBO.corp -resultsize unlimited | set-MailContact-customattribute1 'mail.hmc.lu' Do you think this script may be better written? I've also tried your suggestion with -filter string, but Active Directory don't seems to be able to process the filter string. Any idea? Hi, In my script u can add -OrganizationalUnit and -ResultSize paramerts as they are also supported with get-recipient command Also the filter {$_.customattribute1 -eq ""} is wrong, instead use {$_.customattribute1 -eq $null} Hope this helps. Regards,Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
March 3rd, 2010 10:42pm

Thank you very much for your help. I'll try tomorrow at work.
Free Windows Admin Tool Kit Click here and download it now
March 3rd, 2010 10:47pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics