Convert a mailbox to a shared mailbox or room in Office 365

After migrating mailboxes to O365 many times the 2003 shared mailboxes and room mailboxes were just plain old mailboxes and therefore were brought into the service as vanilla user mailboxes. The problem with this is that they eat a license and in most cases don't need to. Shared mailboxes in O365 don't need a license unless you want them to be larger than 10GB.
Lets use a simple script to convert the mailboxes to either room or shared mailbox depending on the input from a csv file.

First step is the CSV file. We need the file to have a header row with UPN,TYPE and the rest of the lines to be the mailboxes we want to convert. This script assumes that your mailbox UPN is the same as your email address (or one of the email addresses) on the mailbox.
Here's what our sample looks like:

UPN,TYPE
testbox1@contoso.com,Shared
testbox2@contoso.com,Room

Now that we have the input file lets go through the script.

First thing is to read the file so that we can use it.
$mbs=Import-Csv c:\bin\SharedMBs.csv

Now that we have the list we run through it using a foreach loop:

foreach ($mb in $mbs) {
   write-host "********************************************"
   write-host "Working on MB: " $mb.upn
   write-host "Setting Quotas and Type: " $mb.Type
   Set-Mailbox -Identity $mb.upn `
      -Type $mb.Type `
      -IssueWarningQuota 9.5GB `
      -ProhibitSendQuota 9.75GB `
      -ProhibitSendReceiveQuota 10GB
}

This works but what if we wanted to also make sure that the default perms were correct? Lets add a mailbox folder permission command that will set the default user perms to limited details.

foreach ($mb in $mbs) {
   write-host "********************************************"
   write-host "Working on MB: " $mb.upn
   write-host "Setting Quotas and Type: " $mb.Type
   Set-Mailbox -Identity $mb.upn `
      -Type $mb.Type `
      -IssueWarningQuota 9.5GB `
      -ProhibitSendQuota 9.75GB `
      -ProhibitSendReceiveQuota 10GB
   #Set default perms
   $cal=$mb.upn +":\Calendar"
   write-host "Setting Calendar Default Permissions"
   set-MailboxFolderPermission $cal -User Default -AccessRights LimitedDetails
}

One last thing that would be nice is to enable the Room mailboxes for automated calendar processing. This way invites sent to the room will be automatically accepted or denied.

foreach ($mb in $mbs) {
   write-host "********************************************"
   write-host "Working on MB: " $mb.upn
   write-host "Setting Quotas and Type: " $mb.Type
   Set-Mailbox -Identity $mb.upn `
      -Type $mb.Type `
      -IssueWarningQuota 9.5GB `
      -ProhibitSendQuota 9.75GB `
      -ProhibitSendReceiveQuota 10GB
   #Set default perms
   $cal=$mb.upn +":\Calendar"
   write-host "Setting Calendar Default Permissions"
   set-MailboxFolderPermission $cal -User Default -AccessRights LimitedDetails
   #Set Rooms to Autoprocess invites
   if ($mb.Type -eq "Room") {
      write-host "Setting Calendar Processing"
      Set-CalendarProcessing -Identity $mb.upn `
         -AutomateProcessing AutoAccept
   }
}

Now the last part would be removing the E1 license that is set up on the user. This is rather simple we just need to use the Set-MsolUserLicense with the -RemoveLicenses switch. I'm removing the E1 license which is CONTOSO:STANDARDPACK to remove an E3 would be CONTOSO:ENTERPRISEPACK , if you're not sure what your license string is run the Get-MsolAccountSku command to find out.

Here's the loop with the set-msoluserlicense added:

foreach ($mb in $mbs) {
   write-host "********************************************"
   write-host "Working on MB: " $mb.upn
   write-host "Setting Quotas and Type: " $mb.Type
   Set-Mailbox -Identity $mb.upn `
      -Type $mb.Type `
      -IssueWarningQuota 9.5GB `
      -ProhibitSendQuota 9.75GB `
      -ProhibitSendReceiveQuota 10GB
   #Set default perms
   $cal=$mb.upn +":\Calendar"
   write-host "Setting Calendar Default Permissions"
   set-MailboxFolderPermission $cal -User Default -AccessRights LimitedDetails
   #Set Rooms to Autoprocess invites
   if ($mb.Type -eq "Room") {
      write-host "Setting Calendar Processing"
      Set-CalendarProcessing -Identity $mb.upn `
         -AutomateProcessing AutoAccept
   }
   #Remove the E1 License from the user
   Set-MsolUserLicense -UserPrincipalName $mb.upn `
      -RemoveLicenses CONTOSO:STANDARDPACK
}


That's all there is to it. Just make sure to use the correct values for Type. You can find these values at:
http://technet.microsoft.com/en-us/library/bb123981(v=exchg.150).aspx