POWERSHELL: Problem setting primary SMTP address as the External Address in a Mail Contact
I am doing a GWISE to E7K migration and having an issue with how my contacts from GW to Exchange is syncing over. Basically, the GWISE address which is the Target Address/External Address on the Mail Contact is GWISE:<Domain>.<PO>.lastname<sp>firstname. Message flow works fine with this but if I tried to create a mailbox off the mail enabled contact, Exchange does not like the External Address. The manual fix is to set the External address to the SMTP address of the user. I cannot do this for ALL my contacts because message flow will break but I can with the users I migrate. So I like to have a PS to import a .CSV based on email addresses to find the user (IMPORT-CSV), then look at the primarySMTPaddress of the Mail Contact and set that address as the External Address/Target Address. I am not an expert with PS but playing with it and getting close but not close enough. Any help would be great..Mark
December 18th, 2009 8:55pm

Close?$addrs = import-csv addrs.csvforeach ($addr in $addrs){$contact = get-recipient $addrset-mailcontact $contact -externalemailaddress $contact.primarystmpaddress}
Free Windows Admin Tool Kit Click here and download it now
December 18th, 2009 10:15pm

Close?$addrs = import-csv addrs.csvforeach ($addr in $addrs){$contact = get-recipient $addrset-mailcontact $contact -externalemailaddress $contact.primarystmpaddress} I think I am getting close.. I have a .csv csalled addrs.csv and the only entry I have is test23@piercekids.com (no header) I receive an error of:C:\Program Files\Microsoft\Exchange Server\Bin>powershell -psconsolefile exshell.psc1 c:\test3.ps1Get-Recipient : A parameter cannot be found that matches parameter name '@{test23@piercekids.com=}'.At C:\test3.ps1:4 char:25+ $contact = get-recipient <<<< $addrSet-MailContact : Cannot bind argument to parameter 'Identity' because it is null.At C:\test3.ps1:5 char:16+ set-mailcontact <<<< $contact -externalemailaddress $contact.primarystmpaddress}Now if I just run Set-mailcontact test23@piercekids.com –externalemailaddress test23@piercekids.comI can set the contact the way I want but not dynmanically knowing the primary SMTP address. So I am further then I was before. Looks like it is reading the .csv but the script might be slightly off.Thanks for the help.. Any other ideas would be great. I am still playing with this.Mark
December 19th, 2009 4:47pm

If there's only one colmn and no headers in the file, then it's just a text list.get-content addrs.csv |% {set-mailcontact $_ -externalemailaddress $_}
Free Windows Admin Tool Kit Click here and download it now
December 19th, 2009 6:29pm

On Sat, 19-Dec-09 13:47:14 GMT, Witchdoctor120 wrote:arameter cannot be found that matches parameter name '@{test23@piercekids.com=}'.At C:\test3.ps1:4 char:25+ $contact = get-recipient <<<< $addrSet-MailContact : Cannot bind argument to parameter 'Identity' because it is null.At C:\test3.ps1:5 char:16+ set-mailcontact <<<< $contact -externalemailaddress $contact.primarystmpaddress}Now if I just run >>Set-mailcontact test23@piercekids.com ?externalemailaddress test23@piercekids.comI can set the contact the way I want but not dynmanically knowing the primary SMTP address. So I am further then I was before. Looks like it is reading the .csv but the script might be slightly off.Thanks for the help.. Any other ideas would be great. I am still playing with this.Mark Well, if there's no header in the CSV, and there's only one column ofdata, use "get-content" insteaad of "import-csv".It looks like you're also missing a semicolon before the "foreach"statement.Try this:$addrs = get-content addrs.csv; foreach ($addr in $addrs){$contact =cipient $addr; set-mailcontact $contact.distinguishedname-externalemailaddress $contact.primarysmtpaddress.tostring()}---Rich MatheisenMCSE+I, Exchange MVP--- Rich Matheisen MCSE+I, Exchange MVP
December 19th, 2009 8:03pm

Both commands from Rich and mjolinor worked great. Thank you.. The changes get maded but at the EOF of the csv the script throws and error of.. A parameter cannot be found that matches parameter name ''. At :line:1 char:81 + $addrs = get-content c:\addrs.csv; foreach ($addr in $addrs){$contact = recipient <<<< $addr; set-mailcontact $contact.distinguishedname -externalemailaddress $contact.primarysmtpaddress.tostring()}Not a big deal because the script works, just wonder how I can set a flag to single the script is complete without throwing the error..
Free Windows Admin Tool Kit Click here and download it now
December 21st, 2009 6:49am

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

Other recent topics Other recent topics