### Works flawlessly in Office 365 Exchange Online only ### Connect to Exchange Online $Session = New-PSSession -ConfigurationName Microsoft.Exchange ` -ConnectionUri https://outlook.office365.com/powershell-liveid/ ` -Authentication Basic -AllowRedirection -Credential patrick.gruenauer@sid-500.com Import-PSSession $Session -DisableNameChecking $welcome = Get-AcceptedDomain | Where-Object Default -EQ 'True' | Select-Object -ExpandProperty Name Clear-Host Write-Warning "Welcome to the Office 365 Domain $welcome. You are logged in as: $user`n` Exchange Online awaiting your commands." '' Set-Location C:\ ### Get all Mailboxes Get-Mailbox -ResultSize Unlimited ### Disable Auto-Reply on Mailbox Set-MailboxAutoReplyConfiguration -Identity f.huber ` -AutoReplyState Disabled Get-MailboxAutoReplyConfiguration -Identity f.huber | Select-Object Identity,StartTime,EndTime,AutoreplyState ### Set Auto-Reply on User Set-MailboxAutoReplyConfiguration -Identity f.huber ` -InternalMessage "Internal auto-reply message." ` -ExternalMessage "External auto-reply message." ` -AutoReplyState Scheduled ` -StartTime (Get-Date) ` -EndTime (Get-Date).AddDays(30) ### Retrieve Mailboxes that have Auto-Reply enabled Get-Mailbox -ResultSize Unlimited | Get-MailboxAutoReplyConfiguration | Where-Object {$_.AutoReplyState -EQ 'Enabled' -or $_.AutoreplyState -EQ 'Scheduled'} | Select-Object -Property Identity,AutoreplyState,StartTime,EndTime ### Find Active Sync Users Get-CASMailbox -ResultSize Unlimited -Filter {Name -notlike '*Discovery*' -and ` ActiveSyncEnabled -eq $true} Get-CASMailbox -ResultSize Unlimited -Filter {HasActiveSyncDevicePartnership -eq "true"} | Select-Object DisplayName, HasActiveSyncDevicePartnership ### List User Mailboxes by size Get-Mailbox -RecipientTypeDetails UserMailBox -ResultSize Unlimited | Get-MailboxStatistics | Where-Object {!$_.DisconnectDate} | Sort-Object -Property TotalItemSize -Descending | Select-Object DisplayName,ItemCount,TotalItemSize,LastLogonTime #ConvertTo-Html | Set-Content c:\$home\mailboxen.htm ### List Send, SendAs permissions Add-RecipientPermission -Identity f.huber ` -AccessRights SendAs -Trustee patrick.gruenauer -Confirm:$false Get-Mailbox -ResultSize Unlimited | Get-RecipientPermission | Where-Object {$_.Trustee -notlike "*self*"} ### List Mailbox Permissions Add-MailboxPermission -Identity f.huber ` -User patrick.gruenauer -AccessRights FullAccess -InheritanceType all Get-Mailbox -ResultSize Unlimited | Get-MailboxPermission | Where-Object {($_.user.tostring() -notlike "*SELF*") ` -and ($_.user.tostring() -notlike "*S-*") ` -and $_.IsInherited -eq $false -and $_.Identity ` -notlike "*discovery*"} | Select-Object -Property Identity,User,AccessRights Remove-MailboxPermission -Identity f.huber -User patrick.gruenauer ` -AccessRights FullAccess -Confirm:$false ### List Mailboxes with configured Forwarding Address # Server Rules Set-Mailbox -Identity f.huber -ForwardingAddress patrick.gruenauer Set-Mailbox -Identity f.huber -ForwardingSmtpAddress patrick.gruenauer@nowhere.com Get-Mailbox -ResultSize Unlimited ` -Filter "ForwardingAddress -like '*' -or ForwardingSmtpAddress -like '*'" | Select-Object Name,ForwardingAddress,ForwardingSmtpAddress Set-Mailbox -Identity f.huber -ForwardingAddress $null Set-Mailbox -Identity f.huber -ForwardingSmtpAddress $null # Forwarding Rules createy by the user (Outlook) Get-Mailbox -ResultSize Unlimited | Select-Object -ExpandProperty UserPrincipalName | Foreach-Object {Get-InboxRule -Mailbox $_ | Where-Object {($_.redirectto -ne $null) -or ($_.forwardto -ne $null)} | Select-Object -Property MailboxOwnerID,Name,Enabled,From,RedirectTo,ForwardTo} ### List all rules created by the user (Outlook) Get-Mailbox -ResultSize Unlimited | Select-Object -ExpandProperty UserPrincipalName | Foreach-Object {Get-InboxRule -Mailbox $_ | Select-Object -Property ` MailboxOwnerID,Name,Enabled,From,Description,RedirectTo,ForwardTo} ### Show Users LastLogon Time Get-Mailbox -RecipientTypeDetails UserMailBox ` -ResultSize Unlimited -Filter "Name -notlike '*discover*'" | Get-MailboxStatistics | Sort-Object LastLogonTime -Descending | Select-Object DisplayName, MailboxTypeDetail,LastLogonTime,TotalItemSize ### Find orphaned users Get-Mailbox -RecipientTypeDetails UserMailBox ` -ResultSize Unlimited -Filter "Name -notlike '*discover*'" | Get-MailboxStatistics | Where-Object LastLogonTime -LE (Get-Date).AddDays(-1) | Sort-Object LastLogonTime | Select-Object DisplayName, MailboxTypeDetail,LastLogonTime,TotalItemSize