Below are some useful powershell one-liners for Office 365.

Connect to the service

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

Connect-MsolService –Credential $UserCredential

Disconnect from the service

Remove-PSSession $Session

cmdlets

View details of a user

Get-MsolUser -UserPrincipalName [email protected] | FL

Password never expires

# View password never expires setting for all users

Get-MsolUser | Select UserPrincipalName, PasswordNeverExpires

# Enable password never expires for specific user

Set-MsolUser -UserPrincipalName [email protected] -PasswordNeverExpires $true

# Disable password never expires for specific user

Set-MsolUser -UserPrincipalName [email protected] -PasswordNeverExpires $false

# Enable password never expires for all users

Get-MsolUser | Set-MsolUser -PasswordNeverExpires $true

# Disable password never expires for all users

Get-MsolUser | Set-MsolUser -PasswordNeverExpires $false

View list of inactive mailboxes

Retrieves all the mailboxes that has not been accessed for at least 30 days:

Get-StaleMailboxDetailReport

Force start MRM policy

# Force start MRM policy for a single user

Start-ManagedFolderAssistant -Identity "user"

# Force start MRM policy for all users

Get-Mailbox | Start-ManagedFolderAssistant