Here is some useful Powershell Commands for reports:

To install the latest public version of the module, run the following command

Set-ExecutionPolicy RemoteSigned
Install-Module -Name ExchangeOnlineManagement
  • To Connect to Exchange Online with Powershell using modern authetication
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline
Disconnect-ExchangeOnline
  • List All Email Adresses in a .txt file

Get-recipient -resultsize unlimited | select Name -expand emailaddresses > c:\emailadresses.txt

  • List All Mailbox Sizes in a .html file

Get-Mailbox –ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | convertto-html DisplayName, LastLoggedOnUserAccount,  LastLogonTime, TotalItemSize, ItemCount, @{label=”TotalItemSize(MB)”;expression={$_.TotalItemSize.Value.ToMB()}} | set-content c:\mailboxsizes.html

  • List All Mailbox Permissions in a .csv file

Get-Mailbox | Get-MailboxPermission | where {$_.user.tostring() -ne “NT AUTHORITY\SELF” -and $_.IsInherited -eq $false} | Select Identity,User,@{Name=’Access Rights’;Expression={[string]::join(‘, ‘, $_.AccessRights)}} | Export-Csv -NoTypeInformation c:\mailboxpermissions.csv

    Here is some useful Powershell Commands for Database Management:

    • List Mailboxes by mailbox databases

    Get-Mailbox | Sort database, name | Format-Table name, database

    • Move all mailboxes from one database to another database

    1. Launch the Exchange Management Shell > Firstly lets get the names of my Databases, then I can simply copy and paste them into the move mailbox command.

    Get-MailboxDatabase

    Get-Mailbox -Database “Source Database Name” -ResultSize Unlimited | New-MoveRequest -TargetDatabase “Target Database Name

    2. The Mailbox moves should then be queued, depending on how many there are, this can take some time to complete.

    3. To check on progress issue the following command;

    Get-MoveRequestStatistics -MoveRequestQueue “Target Database Name
     

    4. When complete you should remove the movement requests like so;

    Get-MoveRequest | where {$_.status -eq “Completed”} | Remove-MoveRequest
     

    5. That’s all the ‘user’ mailboxes, but your source database server may have system mailboxes in it. These will be either Arbitration mailboxes, or Archive Mailboxes (or both). I don’t have any archive mailboxes, but I do have Arbitration mailboxes. To find out for your databases, use the following commands;

    Get-Mailbox -Database “Source Database Name” -Arbitration

    Get-Mailbox -Database “Source Database Name” -Archive

    6. To move Arbitration and Archive mailboxes, use the following commands;

    Get-Mailbox -Database “Source Database Name” -Arbitration | New-MoveRequest -TargetDatabase “Target Database Name

    Get-Mailbox -Database “Source Database Name” -Archive | New-MoveRequest -TargetDatabase “Target Database Name

    7. Remove all Request

    Get-MoveRequest -ResultSize Unlimited | Remove-MoveRequest -Confirm:$false

    Here is some useful Powershell Commands for Export/Import:

    • Granting User Rights for Mailbox Exports in Exchange 2010

    New-ManagementRoleAssignment -Role “Mailbox Import Export” -User Administrator

    • IMPORT MAILBOX:

    New-MailboxImportRequest -Mailbox “Administrator” -FilePath “\\Exchange\Backup_PSTs\$($i.Alias).pst” 

    • EXPORT MAILBOX:

    New-MailboxExportRequest -Mailbox administrator -FilePath “\\Exchange\Backup_PSTs\$($i.Alias).pst”

    • EXPORT ALL MAILBOXES:

    foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $i -FilePath “\\Exchange\Backup_PSTs\$($i.Alias).pst” }

    • EXPORT ALL USERS FROM OU:

    foreach ($i in (Get-Mailbox -OrganizationalUnit “domain.dk”)) { New-MailboxExportRequest -Mailbox $i -FilePath “\\Exchange\Backup_PSTs\$($i.Alias).pst” }

    • STATUS OF EXPORT:

    Get-MailboxExportRequest | Get-MailboxExportRequestStatistics

    • REMOVE COMPLETED EXPORT REQUESTS :

    GetMailboxExportRequest -Status Completed | Remove-MailboxExportRequest

    • FULL ACCESS TO ALL MAILBOXES

    Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq ‘UserMailbox’) -and (Alias -ne ‘Admin’)} | Add-MailboxPermission -User Administrator@domain.dk -AccessRights fullaccess -InheritanceType all

    Categories: Guides