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 <Database Name> | 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 <ExchangeServerName> -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 <ExchangeServerName> -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 <ExchangeServerName> -Component ServerWideOffline -State Active -Requester Maintenance# Step 6: restart Hub Transport:
Set-ServerComponentState <ExchangeServerName> -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 <Database Name>Get-Mailbox -Database <Database Name> -Archive
Get-Mailbox -Database <Database Name> -Arbitration
Get-Mailbox -Database <Database Name> -PublicFolder
Get-Mailbox -Database <Database Name> -Monitoring
Get-Mailbox -Database <Database Name> -AuditLog
# Step 3
# if the database does have linger shit, move it to a different database with this clause:
# | New-MoveRequest -TargetDatabase <Database Name>
# as such:# this moves all mailboxes
Get-Mailbox -Database <Source Database Name> | New-MoveRequest -TargetDatabase <Destination Database Name>#
Get-Mailbox -Database <Source Database Name> -Archive | New-MoveRequest -TargetDatabase <Destination Database Name>#
Get-Mailbox -Database <Source Database Name> -Arbitration | New-MoveRequest -TargetDatabase <Destination Database Name>#
Get-Mailbox -Database <Source Database Name> -PublicFolder | New-MoveRequest -TargetDatabase <Destination Database Name>#
Get-Mailbox -Database <Source Database Name> -Monitoring | New-MoveRequest -TargetDatabase <Destination Database Name>#
Get-Mailbox -Database <Source Database Name> -AuditLog | New-MoveRequest -TargetDatabase <Destination Database Name># 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 “<Database Name>” | Format-Table Name, CircularLoggingEnabled# enable circular logging
Set-MailboxDatabase “<Database Name>” -CircularLoggingEnabled $True# dismount database for the logging ot take effect
Dismount-Database “<Database Name>” -Confirm:$False# Check the status of the mailbox database
Get-MailboxDatabase “<Database Name>” -Status | Format-Table Name, Mounted# mount the database after you did the above steps
Mount-Database “<Database Name>” -Confirm:$False