Office 365 PowerShell Commands

Office 365 PowerShell Commands


Here are some powershell commands that I used with Office 365 to automate my Cutover migration.  In these examples I'm using my domain skillsinc.com where your domain should be.
These are mostly commands you would use after you have moved your mailboxes to Office 365.

Open the Microsoft Online Services Module for Windows PowerShell
If you want to run any commands that have Msol in them, like Get-MsolUser, you need to run this first:
$Cred = Get-Credential
Connect-MsolService -Credential $cred


If your not running on your ADFS server, you may need to connect to it first with this:
Set-MsolAdfscontext -Computer adfs1

If you want to run any commands that involve the mailboxes, like Get-Mailbox, you need to run this first:$Cred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
https://ps.outlook.com/powershell -Credential $Cred -Authentication:Basic -AllowRedirection
Import-PSSession $Session
Assign Licenses
Check the name of the license pack we need:
Get-MsolAccountSku

Assign everyone the same licenses at one time instead of doing them one at a time in the 365 console. 
This is the the license for Live@EDU Faculty
Get-MsolUser | Set-MsolUserLicense -addlicenses skillsinc:STANDARDWOFFPACK_FACULTY

Assign location
Get-MsolUser | Set-MsolUser -UsageLocation "US”

Set Timezone (Run these two lines one at a time)
$users = Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox')}
$users | %{Set-MailboxRegionalConfiguration $_.Identity -TimeZone "Pacific Standard Time" }

Fix ImmutableId if it's missing (Don't mess with this unless you know for sure why)
$samID = "johndoe"
$searcher = [DirectoryServices.DirectorySearcher] "(samaccountname=$samID)"
$user = $searcher.FindAll()|%{$_.GetDirectoryEntry()}
$guid = [Guid]($user.Properties["objectGUID"][0])
$base64 = [System.Convert]::ToBase64String($guid.ToByteArray())
set-msoluser -UserPrincipalName johndoe@skillsinc.com -ImmutableId $base64


Check to see what everyone ImmutableID is
Get-MsolUser -all | where {$_.isLicensed -eq $true} | select-object userprincipalname,immutableid

Force Removal off all deleted mailboxes from Recycle Bin
Get-MsolUser -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin -Force


Give yourself access to all the mailboxes
Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox') -and (Alias -ne 'ed')} | Add-MailboxPermission -User ed@skillsinc.com -AccessRights fullaccess -InheritanceType all -Automapping $false

Find out how much mail is out there and send it to a text file
Get-User -Filter {RecipientType -eq "UserMailbox"} | Get-MailboxStatistics | ft DisplayName, TotalItemSize, ItemCount | Sort-Object TotalItemSize -Descending > mailboxes.txt

When users are added to the HR inbox they need to be able to forward emails
Add-RecipientPermission HR-Inbox@skillsinc.com -AccessRights SendAs -Trustee hr-user@skillsinc.com

Convert a mailbox into a Room Resource and let people add meetings to it
Set-Mailbox -Identity ConferenceRoom1 -Type Room
Set-MailboxFolderPermission -identity ConferenceRoom1@skillsinc.com:\calendar -user Default -AccessRights Author

Close the session after your done...
Remove-PSSession $Session

More Office 365 tips coming soon!

Comments

Popular posts from this blog

Add your Office 2016 KMS Keys to your Volume Activation Server

Solving WinRM Host connection errors in SCVMM - System Center Virtual Machine Manager 2012 R2

Adding Windows 10 to your Server 2012 R2 KMS Server