Created: 1-19-21

Updated 1-19-21

Below are a few commands I’ve been using along with my 70-345 studies, maybe this well serve others well too!

# Check how many Mailboxes are in databases
Get-Mailbox -ResultSize Unlimited | Group-Object -Property:Database | Select-Object Name, Count | Sort-Object Name | Format-Table

# Check how many mailboxes are in a specific database
Get-Mailbox -ResultSize Unlimited -Database “DB01” | Group-Object -Property:Database | Select-Object Name, Count | Format-Table

# determine the name of the mailbox, the size of the mailbox, and total number of mailbox items
# define the username of the mailbox manually
Get-MailboxStatistics | ft DisplayName,TotalItemSize,ItemCount

# list the mailxboxes in the database
Get-Mailbox -resultsize Unlimited -Database | ft

# Check the state of a mailbox database
Get-MailboxDatabase -Status | % { eseutil /mh $_.edbfilepath } | Out-File c:\temp\OutputFile.txt

# Check the specific state of the database
Get-MailboxDatabase -Status | % { eseutil /mh $_.edbfilepath } | Select-String -Pattern “State:”

# Check Exchange Services Health
test-servicehealth

# Check is Exchange Databases are mounted
Get-MailboxDatabase -Status | Format-List name,server,mounted

# Check to see if there is a mail message queue
Get-Queue | Select Identity,Status,MessageCount

# if mailflow is an issue and you can do it, this script here restarts all services for Exchange
$services = Get-Service | ? { $_.name -like “MSExchange*” -and $_.Status -eq “Running”}
foreach ($service in $services) { Restart-Service $service.name -Force }

#
# Performing updates on an Exchange Server
#

# putting in the Exchange server into maintenacne mode

# Step 1:
# drain all of the mail queues on Exchange Server:
Set-ServerComponentState -Component HubTransport -State Draining -Requester Maintenance

# Step 2:
# to make this change take effect right away, reboot services:
Restart-Service MSExchangeTransport
Restart-Service MSExchangeFrontEndTransport

# Step 3:
# places the Exchange Server into Maintenance mode:
Set-ServerComponentState -Component ServerWideOffline -State Inactive -Requester Maintenance

# Step 4: perform the windows updates
# reboot as necessary

# Step 5: Takes it out of Maint mode:
Set-ServerComponentState -Component ServerWideOffline -State Active -Requester Maintenance

# Step 6: restart Hub Transport:
Set-ServerComponentState -Component HubTransport -State Active -Requester Maintenance

# Step 7: Restart services, to make this change take effect right away, reboot services:
Restart-Service MSExchangeTransport
Restart-Service MSExchangeFrontEndTransport

#
#
# Before deleting a mailbox database perform the following
#
#

# Step 1
# Check how many Mailboxes are in databases
Get-Mailbox -ResultSize Unlimited | Group-Object -Property:Database | Select-Object Name, Count | Sort-Object Name | Format-Table

# Step 2
# Check to make sure the database doesn’t have lingering shit in it
Get-Mailbox -Database

Get-Mailbox -Database -Archive

Get-Mailbox -Database -Arbitration

Get-Mailbox -Database -PublicFolder

Get-Mailbox -Database -Monitoring

Get-Mailbox -Database -AuditLog

# Step 3
# if the database does have linger shit, move it to a different database with this clause:
# | New-MoveRequest -TargetDatabase
# as such:

# this moves all mailboxes
Get-Mailbox -Database | New-MoveRequest -TargetDatabase

#
Get-Mailbox -Database -Archive | New-MoveRequest -TargetDatabase

#
Get-Mailbox -Database -Arbitration | New-MoveRequest -TargetDatabase

#
Get-Mailbox -Database -PublicFolder | New-MoveRequest -TargetDatabase

#
Get-Mailbox -Database -Monitoring | New-MoveRequest -TargetDatabase

#
Get-Mailbox -Database -AuditLog | New-MoveRequest -TargetDatabase

# Step 4
# Now you can delete the mailbox database after its completely empty

#
# Enable Circular logging on a Database
#

# Check if circular logging is enabled on the mailbox database
Get-MailboxDatabase “” | Format-Table Name, CircularLoggingEnabled

# enable circular logging
Set-MailboxDatabase “” -CircularLoggingEnabled $True

# dismount database for the logging ot take effect
Dismount-Database “” -Confirm:$False

# Check the status of the mailbox database
Get-MailboxDatabase “” -Status | Format-Table Name, Mounted

# mount the database after you did the above steps
Mount-Database “” -Confirm:$False