Exchange server - PowerShell commands

Get-command


Get-Command search-mailbox -Module exch16-01.b.co.il

 

 

Get-Command get-* -Module exch16-01.b.co.il

 

 

 

Mailbox migration


New-MoveRequest

Get-moveRequest

Get-moveRequest | get-moverequeststatistics

New-MoveRequest -Identity ana@b.co.il -Priority emergency -TargetDatabase "DB7"

Get-MoveRequest | Remove-MoveRequest

Get-MoveRequest -Identity eugene

Get-MoveRequest -Identity eugene | Remove-MoveRequest

Get-MoveRequestStatistics -Identity eugene

New-MoveRequest -Identity 'itzi@b.co.il' -TargetDatabase "DB7"

 

 

From <https://docs.microsoft.com/en-us/powershell/module/exchange/move-and-migration/new-moverequest?view=exchange-ps>


Get "white space"

Get-MailboxDatabase -Server "exch16-02" -Status | select Name, DatabaseSize, AvailableNewMailboxSpace



How to add Exchange Snapin to Powershell?


Exchange 2007

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

 

Exchange 2010

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

 

Exchange 2013 & 2016

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

 

 

From <http://tech-trainer.info/how-to-add-exchange-snapin-to-powershell/>



Creating RBAC Role To Delegate Contact Management


Get-ManagementRole -Cmdlet New-MailContact

 

 

Get-ManagementRoleEntry –Identity “Mail Recipient Creation\*”

 

 

 

New-ManagementRole –Name AD-Contact-Editors –Parent “Mail Recipient Creation”

 

 

 

Get-ManagementRoleEntry  -Identity AD-Contact-Editors\* | Where-Object {$_.Name -ne 'Get-MailContact'}

 

 

 

Get-ManagementRoleEntry  -Identity AD-Contact-Editors\* | Where-Object {$_.Name -ne 'Get-MailContact'} | Remove-ManagementRoleEntry

 

Get-ManagementRoleEntry –Identity AD-Contact-Editors\*

 

Add-ManagementRoleEntry –Identity “AD-Contact-Editors\New-MailContact”

 

Add-ManagementRoleEntry –Identity “AD-Contact-Editors\Remove-MailContact”

 

Add-ManagementRoleEntry –Identity “AD-Contact-Editors\Get-Recipient”

 

Get-ManagementRoleEntry “AD-Contact-Editors”

 

https://blogs.technet.microsoft.com/rmilne/2013/08/07/creating-rbac-role-to-delegate-contact-management/

 

https://blogs.technet.microsoft.com/rmilne/2013/11/21/creating-rbac-role-to-delegate-editing-contacts/

 

 

 

 Connect or restore a deleted mailbox


To verify that the deleted mailbox that you want to connect a user account to exists in the mailbox database and isn't a soft-deleted mailbox, run the following command:

 

Get-MailboxDatabase | foreach {Get-MailboxStatistics -Database $_.name} | where { $_.DisplayName -eq "<display name>" } | Format-List DisplayName,Database,DisconnectReason

 

The deleted mailbox has to exist in the mailbox database and the value for the DisconnectReason property has to be Disabled. If the mailbox has been purged from the database, the command won't return any results.

 

 

This example connects a deleted user mailbox to a user account that isn't mail enabled. The Identity parameter specifies the display name of the deleted mailbox retained in the mailbox database named MBXDB01. The User parameter specifies the Active Directory user account to connect the mailbox to.

 

Connect-Mailbox -Identity "Paul Cannon" -Database MBXDB01 -User "Robin Wood" -Alias robinw

 

 

https://docs.microsoft.com/en-us/exchange/recipients/disconnected-mailboxes/restore-deleted-mailboxes?view=exchserver-2019