Jump to content

Recommended Posts

Posted

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

Posted
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...

  • Thanks 1
Posted
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?
Posted (edited)

Or could I specify license using job title?

 

$users = Get-MsolUser -Title "Staff"

 

?

Edited by Edu-IT
Posted

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"

  • 1 month later...
Posted
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.
Posted

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.

Posted
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.

Posted

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.

Posted
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.

Posted
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.
Posted (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 by EduTech
Posted
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.

Posted (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 by Edu-IT

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...