Exchange Powershell commands


Adding Send-As rights

get-user -identity “MAILBOX_NAME” | Add-ADPermission -User “USER_ACCOUNT” -ExtendedRights Send-As

Setting maximum number of active sync devices. Typically this only comes up if you're sharing an account across a fair number of devices.

Get-ThrottlingPolicy
Set-ThrottlingPolicy –EASMaxDevices 25 –Identity DefaultThrottlingPolicy_XXXXXXXXX

Exporting mailboxes directly to PST. You only need to assign Management Role Assignment once per admin account.

New-ManagementRoleAssignment -Role "Mailbox Import Export" -User "ADMIN_ACCOUNT"
New-MailboxExportRequest -Mailbox MAILBOX_NAME -FilePath \\ServerName\pst\username.pst
Get-MailboxExportRequest

Finding emails by email address

get-transportserver | Get-MessageTrackingLog -Start "1/01/2017 12:00:00 am" -End "2/21/2017 17:30:00 pm" -resultsize unlimited |where-object {$_.Recipients -like "user@example.com" -AND $_.EventId -eq "receive"}
Get-MessageTrackingLog -Sender "user@example.com" -Recipients "user@example.com" -Start "1/19/2015 8:00AM" | FL Sender,Recipients,MessageSubject,MessageId

Setting up email forwarding

Set-MailboxAutoReplyConfiguration -identity USER_NAME -AutoReplyState enabled -ExternalAudience all -InternalMessage "Internal out of office message." -ExternalMessage "External out of office message."
Set-Mailbox USER_NAME -ForwardingAddress USER_NAME -DeliverToMailboxAndForward $True

Getting list of all the mailboxes and find the mailbox size

$Mailboxes = Get-Mailbox -ResultSize 200
foreach ($Mailbox in $Mailboxes)
{
$Mailbox | Add-Member -MemberType "NoteProperty" -Name "MailboxSizeMB" -Value ((Get-MailboxStatistics $Mailbox).TotalItemSize.Value.ToMb())
}
$Mailboxes | Sort-Object MailboxSizeMB -Desc | Select DisplayName, Alias, PrimarySMTPAddress, MailboxSizeMB | Export-Csv -NoType "C:\Temp\Mailboxes.csv"



Windows Powershell commands


Running updates on a new PC

Powershell.exe -ExecutionPolicy Unrestricted
Install-Module PSWindowsUpdate
Get-WindowsUpdate
Install-WindowsUpdate
Restart-Computer