Exchange: PowerShell Commands

KB ID 0001405

Problem

This might seem like an odd title for an article here at PNL? But I’m going to use this page as a place to put all the commands I’m sick of Googling for, and/or working out every time I do an Exchange job.

So as with all the posts here, it’s here for my benefit, and if anyone else gets something from it great!

Exchange General

Change Exchange Licence Code

[box]Set-ExchangeServer -Identity Server-Name -ProductKey 12345-12345-12345-12345-12345[/box]

Exchange Mailboxes

How Many Mailboxes Per Database?

[box]Get-Mailbox | Group-Object -Property:Database | Select-Object Name,Count | Sort-Object Name | Format-Table -Auto[/box]

 

Exchange Mailbox Migrations

Migrate a Single Mailbox

[box]New-MoveRequest -Identity “Fred Bloggs” -TargetDatabase “Destination-DB” -BatchName “Fred Bloggs” -BadItemLimit “200” -AcceptLargeDataLoss[/box]

Migrate ALL Mailboxes in one Database to Another

[box]Get-Mailbox -Database “Source-DB” ” -ResultSize Unlimited | New-MoveRequest -TargetDatabase “Destination-DB”[/box]

Display Mailbox Migration Progress

[box]Get-moverequest | get-moverequeststatistics

OR

Get-moverequest -MoveStatus InProgress

Get-moverequest -MoveStatus Failed

Get-moverequest -MoveStatus Queued

[/box]

Remove Mailbox Move Requests

[box]Get-MoveRequest -MoveStatus Completed | Remove-MoveRequest[/box]

Exchange Databases

List All Mailboxes in a Database

[box]Get-Mailbox -Database “Database Name“[/box]

Create a Mailbox Database 

[box]New-MailboxDatabase -Name Database-Name -EdbFilePath X:\Folder\Database\Database-Name.edb -LogFolderPath X:\Folder\Log-Folder\[/box]

Show Database (and Log File) Locations

[box]Get-MailboxDatabase -Status | select EdbFilePath
Get-MailboxDatabase -Status | select LogFolderPath[/box]

Move a Database (and Log Files)

[box]Move-DatabasePath -Identity Database-Name -EdbFilePath X:\Folder\Database\Database-Name.edb
Move-DatabasePath -Identity Database-Name -LogFolderPath X:\Folder\Log-Folder\[/box]

Show Mailbox Database ‘Whitespace’

[box]Get-MailboxDatabase -Status | select Name,DatabaseSize,AvailableNewMailboxSpace[/box]

Users and Groups

Exchange Create a Distribution Group

[box]New-DistributionGroup -Name “DG-All-Users” -Type “Security”[/box]

Exchange Add All Users (In an OU) to a Distribution Group

[box]Get-Mailbox -OrganizationalUnit “cn=users,dc=petenetlive,dc=com” -resultsize unlimited|ForEach-Object { Add-DistributionGroupMember -Identity “DG-All-Users” -Member $_ }[/box]

 

Related Articles, References, Credits, or External Links

NA

Leave a Reply

Your email address will not be published. Required fields are marked *