Edu-IT Posted June 5, 2014 Posted June 5, 2014 Does anyone have scripts to do the following that they are willing to share? - Remove Lync license - Add and set as primary an additional SMTP address - Bulk update users email address in their AD account - Bulk set the various policies such as address book, retention, role assignment policy etc
Boredguy Posted June 5, 2014 Posted June 5, 2014 Does anyone have scripts to do the following that they are willing to share? - Remove Lync license - Bulk set the various policies such as address book, retention, role assignment policy etc This post has the script we use for updating the users license and policies - Bulk update users email address in their AD account #Get a list of the users in the Leavers Group $users = Get-ADGroupMember "Students" #Loop through the users FOREACH ($user in $users) { Set-ADUser $user.SamAccountName -EmailAddress ($user.SamAccountName + "@domainamehere.com") } should do what you need without testing it... 1
Edu-IT Posted June 5, 2014 Author Posted June 5, 2014 Thanks for that. I looked at the script and notice you search for STU to identify students. How would I search for a number, let's say if username contains 14, 15 or 16. Do you know? Or would I just run the script three times and replace STU with 14* which I assume would mean the username begins with 14?
Edu-IT Posted June 5, 2014 Author Posted June 5, 2014 (edited) Or could I specify license using job title? $users = Get-MsolUser -Title "Staff" ? Edited June 5, 2014 by Edu-IT
Boredguy Posted June 6, 2014 Posted June 6, 2014 I specify our filter based on the start of the username, but you can use any field that has a value. This would get all our users (synchronised or cloud created) who's office field contains the value "Teaching Staff". $users = Get-MsolUser -All | Where-Object {$_.Office -eq "Teaching Staff" } so for you $users = Get-MsolUser -All | Where-Object {$_.Title -eq "Staff" } would return all users in 365 that have a Title configured as "Staff"
Boredguy Posted July 7, 2014 Posted July 7, 2014 Set-Mailbox -Identity [email protected] -Emailaddresses [email protected],[email protected],[email protected] The first entry after -Emailaddresses is the SMTP that will be the primary one.
Edu-IT Posted July 7, 2014 Author Posted July 7, 2014 Sorry I meant in bulk for all users. I want to add an alias and set that as primary.
FN-GM Posted July 7, 2014 Posted July 7, 2014 Do you use DIRSYNC? If so you need to do that on premise AD not on 365.
Marshall_IT Posted July 7, 2014 Posted July 7, 2014 Get-Mailbox -ResultSize unlimited -Filter {RecipientTypeDetails -eq 'UserMailbox'} | foreach Set-Mailbox -Identity $_ -Emailaddresses [email protected] I've not tested this as I have a DIRsync'd environment but I think this should work.
aceonbass Posted July 8, 2014 Posted July 8, 2014 Mostly on-topic - we're about to switch over to 365 from an on-premise Exchange. I can't disconnect the mailboxes until next week, but once I do this, do I just need to run an internal powershell script to set an attribute which will be picked up by 365 as the address to use when I apply the 365 licenses? We're ADFS 3.0 with DIRSYNC.
EduTech Posted July 8, 2014 Posted July 8, 2014 Hi Edu-IT, In order to create a script that will do what you require it is important to understand where the data is coming from to which you want to add the SMTP Addresses? i.e. are you going to use [email protected] ? or are you looking to use another prefix. Once I know this then it may be possible to pull the data from Active Directory to then create a script that then goes and set's new ProxyAddresses based on information pulled from Active Directory? Unless you have a CSV with the additional proxy addresses we could work with that aswell. Thanks, James.
Edu-IT Posted July 8, 2014 Author Posted July 8, 2014 Hi Edu-IT, In order to create a script that will do what you require it is important to understand where the data is coming from to which you want to add the SMTP Addresses? i.e. are you going to use [email protected] ? or are you looking to use another prefix. Once I know this then it may be possible to pull the data from Active Directory to then create a script that then goes and set's new ProxyAddresses based on information pulled from Active Directory? Unless you have a CSV with the additional proxy addresses we could work with that aswell. Thanks, James. Example. They are provisioned with [email protected]. I want to add, and make the primary, [email protected]. All the domains are added in Office 365.
Marshall_IT Posted July 8, 2014 Posted July 8, 2014 Example. They are provisioned with [email protected]. I want to add, and make the primary, [email protected]. All the domains are added in Office 365. What is their current upn? If it is initialsurname@ then we could use that and select the first section of the string.
EduTech Posted July 8, 2014 Posted July 8, 2014 please test before running in production. Get-Mailbox | % {$newmail = ($_.emailaddresses | ? {$_ -imatch 'SMTP\:\w+\@sub\.edutech\.me\.uk'}) -replace 'sub\.edutech\.me\.uk', 'sub1.edutech.me.uk';$newmail} If you run the following it will give you an output and allow you to see the changes, so what this does is take all of your existing SMTP addresses for the users and it will grab the existing domain and then using regex will then add an SMTP address that matches the existing pre-fix with the new domain. If you run the above command, it will output it to powershell console.. have a look over it and see if that is what you want to do. if it is, then i shall give you the command to write these values back. :-) NOTE you have to replace my domain with yours... and for each . you need to put a \ before hand. hopefully you follow my logic. James.
EduTech Posted July 8, 2014 Posted July 8, 2014 Doesn't seem to do anything? can you send me a PM with the command that you run i imagine you didn't replace the syntax correctly. James.
Edu-IT Posted July 8, 2014 Author Posted July 8, 2014 Ah I know why. That seems to work but I have some uppercase SMTP and some lower showing?
Edu-IT Posted July 8, 2014 Author Posted July 8, 2014 What is their current upn? If it is initialsurname@ then we could use that and select the first section of the string.Their current UPN is what I want to use, yes.
EduTech Posted July 8, 2014 Posted July 8, 2014 (edited) ok, do the following command first against a test account to make sure it does what you want.. Get-Mailbox [email protected] | % {$mail = $_.EmailAddresses -creplace 'SMTP', 'smtp';$mail += "SMTP:$($_.UserPrincipalName)";Set-Mailbox -Identity $_.UserPrincipalName -EmailAddresses $mail} If that works fine then you can run this and it will do it for them all. Get-Mailbox | % {$mail = $_.EmailAddresses -creplace 'SMTP', 'smtp';$mail += "SMTP:$($_.UserPrincipalName)";Set-Mailbox -Identity $_.UserPrincipalName -EmailAddresses $mail} Regards, James. Edited July 8, 2014 by EduTech
EduTech Posted July 8, 2014 Posted July 8, 2014 What parts do I need to change in that? the first command you just need to replace [email protected] so that you can do a test, and then the second command you don't need to change anything it will do it for all users. James.
Edu-IT Posted July 8, 2014 Author Posted July 8, 2014 (edited) please test before running in production. If you run the following it will give you an output and allow you to see the changes, so what this does is take all of your existing SMTP addresses for the users and it will grab the existing domain and then using regex will then add an SMTP address that matches the existing pre-fix with the new domain. If you run the above command, it will output it to powershell console.. have a look over it and see if that is what you want to do. if it is, then i shall give you the command to write these values back. :-) NOTE you have to replace my domain with yours... and for each . you need to put a \ before hand. hopefully you follow my logic. James. So I need to run this first, then that one? Reason I ask is that I can't see how the script knows what domain to use? Get-Mailbox | % {$mail = $_.EmailAddresses -creplace 'SMTP', 'smtp';$mail += "SMTP:$($_.UserPrincipalName)";Set-Mailbox -Identity $_.UserPrincipalName -EmailAddresses $mail} Edited July 8, 2014 by Edu-IT
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now