Exchange online – Office 365 – PowerShell

To connect via PowerShell to office365/Exchange online you need:

Pre-Requisites:

To connect to Exchange Online run:

Connect-ExchangeOnline
and when prompted enter your creds:

To verify:

Get-PSSession | fl
 

Exchange 2013 and 2016 Server maintenance

I have a two node DAG with the servers ex01 and ex02. I will be putting ex01 into maintenance mode:
1. Launch Exchange Management Shell
2. Use the Set-ServerComponentState command to set the HubTransport component into a draining state
3. Set-ServerComponentState ex01 –Component HubTransport –State Draining –Requestor Maintenance
4. Use the Redirect-Message command to redirect messages currently in the queue – You may get an error message here.
5. Redirect-Message –Server ex01 –Target ex02
6. Use the Suspend-ClusterNode command to pause ex01 from participating in the cluster
7. Suspend-ClusterNode –Name ex01
8. Disable the database copy auto-activation on ex01
9. Set-MailboxServer ex01 –DatabaseCopyActivationDisabledAndMoveNow $true
10. Set DatabaseCopyAutoActivationPolicy to blocked
11. Set-MailboxServer ex01 –DatabaseCopyAutoActivationPolicy Blocked
12. Confirm that there are no Databases mounted on ex01. The command below should return no results.
13. Get-MailboxDatabaseCopyStatus –Server ex01 | Where {$_.Status –eq “Mounted”}
14. If mailboxes are still on ex01 move them to ex02.
15. Move-ActiveMailboxDatabase DB1 -ActivateOnServer ex02
16. Now place the server in Maintenance Mode
17. Set-ServerComponentState ex01 –Component ServerWideOffline –State InActive –Requestor Maintenance

At this point I can perform my maintenance on ex01 (i.e Windows/Exchange updates etc.).
And here are the steps below to bring it back into the cluster.
1. Take ex01 out of maintenance mode
2. Set-ServerComponentState ex01 –Component ServerWideOffline –State Active –Requestor Maintenance
3. Resume cluster operations on ex01
4. Resume-ClusterNode –Name ex01
5. Set Database Copy Auto Activation Policy to Unrestricted
6. Set-MailboxServer ex01 –DatabaseCopyAutoActivationPolicy Unrestricted
7. Set Database Copy Activation Disabled and Move to FALSE
8. Set-MailboxServer ex01 –DatabaseCopyActivationDisabledAndMoveNow $false
9. Set the Hub Transport component to Active
10. Set-ServerComponentState ex01 –Component HubTransport –State Active –Requester Maintenance

JOB DONE

PS Exchange – Setting up quotas

To check quotas on a DB:

Get-MailboxDatabase -Identity DB | Format-List *Quota

ProhibitSendReceiveQuota     : unlimited
ProhibitSendQuota            : 1000 MB (1,048,576,000 bytes)
RecoverableItemsQuota        : 30 GB (32,212,254,720 bytes)
RecoverableItemsWarningQuota : 20 GB (21,474,836,480 bytes)
IssueWarningQuota            : 900 MB (943,718,400 bytes)

To Set

$databaseQuota = @{
    'Identity' = "DB"
    'IssueWarningQuota = '2GB'
    'ProhibitSendQuota' = '10GB'
}
Set-MailboxDatabase @databaseQuota

To set user quotas

Get-mailbox -id $mailbox | fl *quota,UseDatabaseQuotaDefaults

If the userDatabaseQuotaDefaults is set to $true then DB values apply
To set user quota:

$userQuota = @{
    'Identity' = $Mailbox
    'IssueWarningQuota = '20GB'
    'ProhibitSendQuota' = '22GB'
    'userDatabaseQuotDefaults' = $false
}
Set-mailbox @UserQuota

PS Exchange – Mailbox Permissions

To see permissions on a mailbox:
Get-MailboxPermission -Identity User| where isinherited -eq $false

Snippet to add permissions:
Add Full access:

$MailboxPermission = @{
    'identity' = "Bob Harris"
    'user' = "Bill Goat"
    'AccessRights' = 'FullAccess'.'DeleteItem'
    'AutoMapping' = $true
}
Add-MailboxPermission @MailboxPermission

Possible permissions: FullAccess, SendAs, ExternalAccount, DeleteItem, ReadPermission, ChangePermission, ChangeOwner

To Remove Full Access:
Remove-MailboxPermission -identity "Bob Harris" -User "Bill Goat" -AccessRights DeleteItem -Confirm:$false