EXT email address
Hello, I use Exch 2007 and I used to use the first part of the script which help me to creat the user in my organization: import-csv "C:\Scripts\ACCOUNT_CREATION\ACCOUNT.csv" | foreach {enable-MailUser -identity $_.identity -ExternalEmailAddress $_.ExternalEmailAddress} | Set-Mailuser -emailaddresspolicyenabled:$True The thing is that I need now to change the user externalemailaddress based on the Alias and the organizational unit. For instance based on the below PS1 the users after being created (see the above script I mentionned before) should have their externalemailaddress looking like as: "alias of PS1"@company.intra "alias of PS2"@uk.company.intra In fact my script does work but do not distinguish between the company.intra and uk.company.intra .. I guess I should insert an IF organizational unit start with "uk.company.intra" = foreach{$ExternalEmailAddress = "$($_.Alias)@MYCPY.INTA"; Set-Mailuser $_.Identity -ExternalEmailAddress $ExternalEmailAddress} but I do not know how to manage that command PS1: START Identity,ExternalEmailAddress company.intra/User Test Exchange/ps1 ps1,"ps1.ps1@mycompany.com" uk.company.intra/User Test Exchange/ps1 ps1,"ps1.ps1@mycompany.com" END SCRIPT: START import-csv "C:\Scripts\ACCOUNT_CREATION\ACCOUNT.csv" | foreach {enable-MailUser -identity $_.identity -ExternalEmailAddress $_.ExternalEmailAddress} | Set-Mailuser -emailaddresspolicyenabled:$True import-csv "C:\Scripts\ACCOUNT_CREATION\ACCOUNT.csv" |Get-Mailuser | foreach{$ExternalEmailAddress = "$($_.Alias)@MYCPY.INTA"; Set-Mailuser $_.Identity -ExternalEmailAddress $ExternalEmailAddress} Start-EdgeSynchronization END CAN YOU PLEASE HELP ME OUT??? Thank to all in advance Graig
November 11th, 2010 9:52am

The mailuser object doesn't have an organizationalunit property, but you can use the distinguishedname property to do your test. if ((get-mailuser $_.identity).distinguishedname -like "*ou=uk,dc=company,dc=intra"){ set-mailuser $_.Identity -ExternalEmailAddress <external address for UK subdomain> } else {set-mailuser $_.Identity -ExternalEmailAddress <external address for not UK subdomain>} }[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 11th, 2010 10:17am

Thanks mjolinor, In fact you help me out with that commad: import-csv "C:\Scripts\ACCOUNT_CREATION\ACCOUNT.csv" | foreach {enable-MailUser -identity $_.identity -ExternalEmailAddress $_.ExternalEmailAddress} | Set-Mailuser -emailaddresspolicyenabled:$True --> How do I combine the above command with the command you gave me? I check at the DistinguishedName and I got for the 2 users in the exemple: DC=company,DC=intra DC=uk,DC=company,DC=intra The csv file is a file I receive whenever an account has to be created (AD team extract it and save it in a path), Then the ps1 file is creating the user but I need to change the external email address for any new user (alias@DC=company,DC=intra -> then alias@company.intra) I could ot manage to make your command work maybe I have done something wrong.. Can you provide me further info please?
November 11th, 2010 10:43am

If that's what your dn's look like, then the example would change to: if ((get-mailuser $_.identity).distinguishedname -like "*dc=uk,dc=company,dc=intra"){ set-mailuser $_.Identity -ExternalEmailAddress <external address for UK subdomain> } else {set-mailuser $_.Identity -ExternalEmailAddress <external address for not UK subdomain>} } Basically you're testing the dn of the user to see if it ends with dc=uk,dc=company,dc=intra. If it does, give it an external address for the uk.company.intra organizationalunit, otherwise give it an address and address for the company.intra organizational unit. [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 11th, 2010 10:52am

Also, I'm not quite getting what your after. I can't really tell from the description if you're wanting to change the external address of existing users, after they have been created and mail enabled, or set the address based on their OU when you first mail enable them.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
November 11th, 2010 10:55am

Clearly, I receive a csv file when new hires come to my company, and the csv looks like: PS1: START Identity,ExternalEmailAddress company.intra/User Test Exchange/ps1 ps1,"ps1.ps1@mycompany.com" uk.company.intra/User Test Exchange/ps1 ps1,"ps1.ps1@mycompany.com" END From that csv file I need to create the user as I used to do it with that command: import-csv "C:\Scripts\ACCOUNT_CREATION\ACCOUNT.csv" | foreach {enable-MailUser -identity $_.identity -ExternalEmailAddress $_.ExternalEmailAddress} | Set-Mailuser -emailaddresspolicyenabled:$True --> My goal is to set as an external email address: alias@company.intra knowing that I have domain and sub domain so one can look like ps1ps1@company.intra and the other one ps2ps2@uk.company.intra If fact, If I run that script: import-csv "C:\Scripts\ACCOUNT_CREATION\ACCOUNT.csv" | foreach {enable-MailUser -identity $_.identity -ExternalEmailAddress $_.ExternalEmailAddress} | Set-Mailuser -emailaddresspolicyenabled:$True AND after I run that one: import-csv "C:\Scripts\ACCOUNT_CREATION\ACCOUNT.csv" |Get-Mailuser | foreach{$ExternalEmailAddress = "$($_.Alias)@company.intra"; Set-Mailuser $_.Identity -ExternalEmailAddress $ExternalEmailAddress} it will accomplish what I and expected.. but it will not do the difference between @company.intra and @uk.company.intra I hope I have been clearer. Please do not hesitate to tell me if I haven't. Thanks, Graig
Free Windows Admin Tool Kit Click here and download it now
November 11th, 2010 11:26am

OK. I'm a little confuse by "ps1ps1@company.intra and the other one ps2ps2@uk.company.intra". It seems like you want to set the domain portion of the address based on the OU of the user object, but what's the difference between ps1ps1 and ps2ps2. I see where you're getting ps1 from. What's ps2?[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
November 11th, 2010 11:35am

Detail of the users: first name = ps1 Last name = ps1 Identity = ps1ps1 email address: ps1.ps1@compmay.com External email address: ps1ps1@company.intra first name = ps2 Last name = ps2 Identity = ps2ps2 email address: ps2.ps2@compmay.com External email address: ps2ps2@uk.company.intra Domain: company.intra Sub Domain: uk.company.intra I hope it gets clearer :-S thanks again for your interest!!
Free Windows Admin Tool Kit Click here and download it now
November 11th, 2010 1:04pm

Try this. If it's not what your after, I'm out of ideas. import-csv "C:\Scripts\ACCOUNT_CREATION\ACCOUNT.csv" |Get-Mailuser | foreach{ if ((get-user $_.identity).distinguishedname -like "*dc=uk,dc=company,dc=intra*" ){ $ExternalEmailAddress = "$($_.Alias)@uk.company.intra" } else { $ExternalEmailAddress = "$($_.Alias)@company.intra" } Set-Mailuser $_.Identity -ExternalEmailAddress $externalEmailAddress }[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
November 11th, 2010 1:36pm

Reading the command it seems good to me but how do I insert the "enable-MailUser" in that command? Because as the account has not been yet created on Exchange I got an error message running that script.
Free Windows Admin Tool Kit Click here and download it now
November 12th, 2010 6:52am

OK, now I understand the problem a little better. I was confused by the statement that the AD team was providing you with the csv. I assumed that if you had a separate AD team, they would take care of the creation of user accounts. It seems irrational they would delegate that to the Exchange admin. I'll have to invesigate scripting of new user accounts with just the Exchange cmdlets when I get to work.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
November 12th, 2010 7:22am

I agree with you mjolinor.. It is odd that AD is handled by another team.. But I have to cope with it.. I really appreciate your help. Thanks a lot and sorry for the confusion, I haven't exposed the full situation to you. Lokk forward to hearing from you :-D Graig
Free Windows Admin Tool Kit Click here and download it now
November 12th, 2010 7:35am

It's not really odd that AD is handled by another team. Many organizations do that. It is odd that AD is handled by another team, but they aren't provisioning the user accounts. Creatiing a user account involves things like setting up the account with the appropropriate security groups, setting the intial password and communicating that to the user, creation of the user home direcory, assigning logon scripts, etc. Normally you'd do all that before you start setting up their email accounts.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
November 12th, 2010 7:44am

You need to replace enable-mailuser with new-mailuser. See get-help new-mailuser -full | more for details on the cmdlet.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 12th, 2010 8:55am

Well AD account is created. I do the enable-MailUser to create it on the EMC... The csv file is sent from the AD team and the provided me fields I requested to be able to create user automatically (Scheduling my ps1 file on my server base on the csv file location/path). But as I need to change the external email address of new created account, I requested your help, as I do not know how to managed that.. As I said before the script I used (and that provided me - THANKS!!) do a perfect job and answer my expectation. I would just wish to add to that script the possibility to rename the external email address as I told you: (alias@uk.company.com if user hosted on the uk.company.com subdomain OR alias@compny.com if the user id hosted on the company.com domain). Thanks again for your interest!
November 12th, 2010 8:55am

Best guess: import-csv "C:\Scripts\ACCOUNT_CREATION\ACCOUNT.csv" | foreach { if ((get-user $_.identity).distinguishedname -like "*dc=uk,dc=company,dc=intra*" ){ $ExternalEmailAddress = "$($_.Alias)@uk.company.intra" } else{ $ExternalEmailAddress = "$($_.Alias)@company.intra" } } enable-MailUser -identity $_.identity -ExternalEmailAddress $ExternalEmailAddress} | Set-Mailuser -emailaddresspolicyenabled:$True [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 12th, 2010 10:45am

Hello, I got the error message: You must provide a value expression on the right-hand side of the '-' operator. At C:\Scripts\AUTO-UPDATE\ACCOUNT.ps1:1 char:329 I first thought that a missing "{" was not present in the end of the comman (see below). but I can not make it work by adding the { enable-MailUser -identity $_.identity -ExternalEmailAddress $ExternalEmailAddress} | Set-Mailuser -emailaddresspolicyenabled:$True Graig
November 15th, 2010 5:54am

On Mon, 15 Nov 2010 10:49:48 +0000, Graiggoriz wrote: >I got the error message: > >You must provide a value expression on the right-hand side of the '-' operator. At C:\Scripts\AUTO-UPDATE\ACCOUNT.ps1:1 char:329 > >I first thought that a missing "{" was not present in the end of the comman (see below). but I can not make it work by adding the { > >enable-MailUser -identity $_.identity -ExternalEmailAddress $ExternalEmailAddress} | Set-Mailuser -emailaddresspolicyenabled:$True It looks like the last "}" is misplaced. Try removing it and placing it at the end of the last line. " } enable-MailUser -identity $_.identity -ExternalEmailAddress $ExternalEmailAddress} | Set-Mailuser -emailaddresspolicyenabled:$True" Should be: "enable-MailUser -identity $_.identity -ExternalEmailAddress $ExternalEmailAddress} | Set-Mailuser -emailaddresspolicyenabled:$True }" .. . . without the quotation marks, of course. --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
November 15th, 2010 11:29am

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

Other recent topics Other recent topics