Filtering email addresses
Hi! I need to create a Script that adds one SMTP address if the user doesn't have it and I was thinking about something like get-mailbox -ResultSize Unlimited | where{$_.EmailAddresses -notlike "smtp:*@themailIwanttoadd.com"} To find the mailboxes, the thing is the cmdlet is showing me all the mailboxes and not only the ones that doesn't have the address... any tips anyone?:) Thanks in advance!
January 18th, 2011 9:50am

This script isn’t “adding” anything. Are you only posting a snippet? Are you trying to set the Windows “mail” attribute, or an Exchange proxy address? If you just want to fill the users “mail” attributes, try this: Get-QADUser –SearchRoot “contoso.local/My Users” –SizeLimit 0 | Where {$_.mail –eq -$null} | ForEach-Object ($_.samaccountname) {$CompleteEmail = $_.Samaccountname +"@contoso.local" ; Set-QADUser -Identity $_.SamAccountName} -ObjectAttributes @{mail=$CompleteEmail} This assumes their email address uses their samaccountname. The cmdlets used here are part of this free download: http://www.quest.com/powershell/activeroles-server.aspx Mike Crowley Check out My Blog!
Free Windows Admin Tool Kit Click here and download it now
January 18th, 2011 10:31am

If you are just looking to extract the accounts with no SMTP address you could try the one below. get-mailbox -ResultSize Unlimited | where{$_.PrimarySMTPAddress -like $null} Emailaddresses is not a single value hence it would give you unexpected results. Please let me know if you want to look into emailaddresses only so that i can modify the command as per your requirement.
January 19th, 2011 1:47am

I'm posting only the line I want to use to get the mailboxes without the address I want to add. If that is a snippet then I'm posting one :) The thing is: I need to add one mail address to users who dont have it. In the same server are users who already have it and even users who have two other addresses as well so, to be code-polite I was thinking a way to select ONLY the mailboxes that don't have the address instead of setting the mail address to ALL the users. So I separated the scrpt in two parts (snippets??:) 1° select the users (only those who don't have the address) 2° Adding the mail address Take the active address name (ie: the 'jcontoso' from 'jcontoso@blabla.com') Adding a new EmailAddresses (jcontoso@otherdomain.com) Rajitha: Can I redefine your get-mailbox to look into EmailAddresses only for a single address? Thank you!!
Free Windows Admin Tool Kit Click here and download it now
January 19th, 2011 8:46am

it would not work that way as emailaddresses has multiple values and primarysmtpaddress is a single valued attribute...i will get back to you with the modified one
January 19th, 2011 8:50am

See if this works better: get-mailbox -ResultSize Unlimited | where{[string]($_.EmailAddresses) -notlike "*@themailIwanttoadd.com*"}[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
January 19th, 2011 9:26am

I solved It! The users I need to modify ahve the same Primary Smtp Address, Thanks Rajitha! Now I need to run something that add a new address taking the primary and changing the 'at' part. I figured out something like this: Get-Mailbox -ResultSize Unlimited | where{$_.PrimarySMTPAddress -like "*@ciudad.bco"} | $usr = $a.primarysmtpaddress.tostring().split("@")[0] | $newaddrs = @() | $newaddrs += $usr + "@bcba.com.ar" | Set-Mailbox -PrimarySMTPAddress $newaddrs Thing is only expressions are allowed as first element of a pipeline...... Maybe something with a 'foreach'??
January 19th, 2011 9:28am

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

Other recent topics Other recent topics