Remote Powershell with Exchange Online

2/11/2014

Whenever I need to run some powershell commands on an Office 365 Exchange server, I always end up scouring the internet looking for commands and walkthroughs. Below Is an excerpt from a list a coworker of mine put together with a few extra commands that I added in myself. Enjoy!

 First, you want to install  the “Windows Azure Active Directory Module for Windows PowerShell” from  http://technet.microsoft.com/en-us/library/jj151815.aspx.  You can install this anywhere.

Using this tool you can connect to Office 365 with the following
commands

 $cred = Get-Credential     (log in using your Office 365 username and password when prompted)
$session = New-PSSession -ConfigurationName Microsoft.Exchange
-ConnectionUri
https://ps.outlook.com/powershell/ -Credential $cred -Authentication Basic
-AllowRedirection

 Import-PSSession $session

And then from here you can run any Exchange PowerShell command you like.

If you are using DirSync at the client site You can check the status using:

Connect-MsolService
 (Get-MsolCompanyInformation).DirectorySynchronizationEnabled


 You can change the status (enable or disable DirSync)

 Set-MsolDirSyncEnabled –EnableDirSync $false    (or $true to enable)

You can give an account full access to all current mailboxes for migration purposes

Get-Mailbox  -ResultSize Unlimited | Add-MailboxPermission -AccessRights FullAccess
-Automapping $false -User insertnamehere

If you have delete users from Office 365 portal and need to remove them from Delete users

List Deleted users

Get-MsolUser -ReturnDeletedUsers

Delete deleted users

Get-MsolUser –ReturnDeletedUsers | foreach { Remove-MsolUser -ObjectId $_.ObjectId
-RemoveFromRecycleBin -Force }


Disable Password Complexity

Get-MsolGroupMember -groupObjectid <id> | Set-MsolUser -StrongPasswordRequired $False

 Run the following command to set users’ passwords to never to expire.

 Get-MsolGroupMember -groupObjectid <id> | Set-MsolUser -PasswordNeverExpires $true

If this guide helped you out, feel free to share a link or buy me a beer/coffee below :-)

**Full Disclosure**
I don't make money from this site and I don't have any intention of monetizing. Thanks to a few kind souls who recently made a few generous donations, I was motivated to migrate this site to github. I'm hoping things will continue to function as well as it did on Weebly but web development is not my expertise so I'm learning as I go. If you'd like to encourage further development or just say thanks, I've provided a donation link below. Thanks again guys!