{"id":1507,"date":"2017-03-13T12:22:11","date_gmt":"2017-03-13T19:22:11","guid":{"rendered":"http:\/\/jim-zimmerman.com\/?p=1507"},"modified":"2023-06-21T10:40:51","modified_gmt":"2023-06-21T17:40:51","slug":"more-exchange-management-shell-commands","status":"publish","type":"post","link":"https:\/\/jim-zimmerman.com\/?p=1507","title":{"rendered":"More Exchange Management Shell commands"},"content":{"rendered":"<p>To set a forwarding address for a mailbox that will also deliver the message to the Identity&#8217;s mailbox:<\/p>\n<blockquote><p>Set-Mailbox -Identity <em>identityname<\/em> -DeliverToMailboxAndForward $true -ForwardingSMTPAddress &#8220;<em>my@mail.address<\/em>&#8220;<\/p><\/blockquote>\n<p>Note: If DeliverToMailboxAndForward is $false, then the message will not be deliver to the Identity&#8217;s mailbox.  Just forwarded.<\/p>\n<p>To remove a forwarding address for a mailbox:<\/p>\n<blockquote><p>Set-Mailbox -Identity <em>identityname<\/em> -ForwardingSMTPAddress $null -ForwardingAddress $null<\/p><\/blockquote>\n<p>To delete email from a mailbox:<br \/>\nSearch-Mailbox -Identity <em>someuser<\/em> -SearchQuery &#8216;Received:<MM\/DD\/YYYY' -DeleteContent\nSearch-Mailbox -Identity <em>someuser<\/em> -SearchQuery &#8216;Sent:<MM\/DD\/YYYY' -DeleteContent\n\nTo list auto reply status for an account:\n\n\n<blockquote>Get-MailboxAutoReplyConfiguration <em>accountname<\/em> | Format-List<\/p><\/blockquote>\n<p>To disable auto reply for an account:<\/p>\n<blockquote><p>Set-MailboxAutoReplyConfiguration <em>accountname<\/em> -AutoReplyState:disabled<\/p><\/blockquote>\n<p>To add an email address to a mailbox:<\/p>\n<blockquote><p>Set-Mailbox <em>accountname<\/em> -EmailAddresses @{add=&#8221;<em>email@address.domain<\/em>&#8220;}<\/p><\/blockquote>\n<p>To only restore the Inbox for a mailbox:<\/p>\n<blockquote><p>Restore-Mailbox -Identity <em>restoreto<\/em> -RecoveryDatabase <em>recoverydbname<\/em> -RecoveryMailbox <em>restorefrom<\/em> -Target <em>targetfolder<\/em> -IncludeFolders \\<em>Inbox<\/em><\/p><\/blockquote>\n<p>To disable a mailbox means to disconnect a mailbox from an account.  It doesn&#8217;t remove either the account or the mailbox.  All Exchange attributes will be removed from the account and the mailbox will be in a disabled state.  Note:  The mailbox does not immediatley show up in the disabled mailbox list until the Clean-MailboxDatabase process runs again.  This periodically happens on the system, but can be forced with the Clean-MailboxDatabase command.  To disable a mailbox:<\/p>\n<blockquote><p>Disable-Mailbox -Identity &#8220;<em>Display Name<\/em>&#8220;<\/p><\/blockquote>\n<p>Update list of disabled mailboxes:<\/p>\n<blockquote><p>Clean-MailboxDatabase &#8220;<em>Mailbox Database Name<\/em>&#8220;<\/p><\/blockquote>\n<p>To list all disabled mailboxes:<\/p>\n<blockquote><p>Get-MailboxDatabase | Get-MailboxStatistics | Where { $_.DisconnectReason -eq &#8220;Disabled&#8221; }<\/p><\/blockquote>\n<p>To connect a mailbox to a user account:<\/p>\n<blockquote><p>Connect-Mailbox -Database <em>DatabaseName<\/em> -Identity &#8220;<em>Mailbox Display Name<\/em>&#8221; -User <em>accountname<\/em><\/p><\/blockquote>\n<p>Note: For the Identity or User, you can use the Legacy DN.  I found this useful, when I had two of the same Display Name mailboxes disabled at the same time.  You can determine the Legacy DN using the following:<\/p>\n<blockquote><p>Get-MailboxDatabase | Get-MailboxStatistics | Where { $_.DisconnectReason -eq &#8220;Disabled&#8221; | Select DisplayName,LegacyDN}<\/p><\/blockquote>\n<p>To check you send filter configuration:<\/p>\n<blockquote><p>Get-SenderFilterConfig<\/p><\/blockquote>\n<p>Note: This will override the current setting and only block the one address.<br \/>\nTo block a user:<\/p>\n<blockquote><p>Set-SenderFilterConfig -BlockedSenders <em>emailaddress<\/em><\/p><\/blockquote>\n<p>To block more than one:<\/p>\n<blockquote><p>Set-SenderFilterConfig -BlockedSenders <em>emailaddress1<\/em>,<em>emailaddress2<\/em><\/p><\/blockquote>\n<p>To block an entire domain:<\/p>\n<blockquote><p>Set-SenderFilterConfig -BlockedDomains <em>domainname<\/em><\/p><\/blockquote>\n<p>The BlockedSenders and BlockedDomains are &#8220;Multivalue properties&#8221;, so to add or remove entries instead of entering all them every time you just want to add one, you can do the following:<\/p>\n<blockquote><p>Set-SenderFilterConfig -BlockedSenders @{Add=&#8221;<em>emailaddress1<\/em>&#8220;, &#8220;<em>emailaddress2<\/em>&#8220;}<\/p><\/blockquote>\n<p>Or:<\/p>\n<blockquote><p>Set-SenderFilterConfig -BlockedDomains @Add={&#8220;<em>domainname1<\/em>&#8220;, &#8220;<em>domainname2<\/em>&#8220;<\/p><\/blockquote>\n<p>Same idea to remove from the list:<\/p>\n<blockquote><p>Set-SenderFilterConfig -BlockedSenders @{Remove=&#8221;<em>emailaddress1<\/em>&#8220;, &#8220;<em>emailaddress2<\/em>&#8220;}<\/p><\/blockquote>\n<p>Or:<\/p>\n<blockquote><p>Set-SenderFilterConfig -BlockedDomains @Remove={&#8220;<em>domainname1<\/em>&#8220;, &#8220;<em>domainname2<\/em>&#8220;<\/p><\/blockquote>\n<p>Managing message size:<br \/>\nHere are the places where sending and receiving message size can be managed:<\/p>\n<blockquote><p>Get-TransportConfig | FL<\/p><\/blockquote>\n<blockquote><p>Get-ReceiveConnector | FL<\/p><\/blockquote>\n<blockquote><p>Get-SendConnector | FL<\/p><\/blockquote>\n<blockquote><p>Get-Mailbox <em>mailbox<\/em> | FL<\/p><\/blockquote>\n<p>You want too look at the MaxSendSize, MaxReceiveSize settings.<\/p>\n<blockquote><p>Get-TransportConfig | FT MaxSendSize, MaxReceiveSize<\/p><\/blockquote>\n<blockquote><p>Get-ReceiveConnector | FT MaxMessageSize<\/p><\/blockquote>\n<blockquote><p>Get-SendConnector | FT Name,MaxMessageSize<\/p><\/blockquote>\n<blockquote><p>Get-Mailbox <em>mailbox<\/em> | FT Name,MaxSendSize, MaxReceiveSize<\/p><\/blockquote>\n<p>get-transportconfig | Set-TransportConfig -maxsendsize 15MB -maxreceivesize 15MB; get-receiveconnector | set-receiveconnector -maxmessagesize 10MB; get-sendconnector | set-sendconnector -maxmessagesize 10MB; get-mailbox | Set-Mailbox -Maxsendsize 10MB -maxreceivesize 10MB<\/p>\n<p>To modify the limits:<\/p>\n<blockquote><p>Set-TransportConfig -MaxSendSize 100MB -MaxReceiveSize 100MB<\/p><\/blockquote>\n<blockquote><p>Set-ReceiveConnector -MaxMessageSize 100MB<\/p><\/blockquote>\n<blockquote><p>Set-SendConnector <em>connectorname<\/em> -MaxMessageSize 100MB<\/p><\/blockquote>\n<blockquote><p>Get-Mailbox <em>mailbox<\/em> | Set-Mailbox -MaxSendSize 100MB -MaxReceiveSize=100MB<\/p><\/blockquote>\n<p>There is a way to limit the attachment size itself, but creating a transport rule:<\/p>\n<blockquote><p>New-TransportRule -Name <em>GTHMaxAttachSize<\/em> -AttachmentSizeOver 100MB -RejectMessageReasonText &#8220;This attachment is too big!  What were you thinking?&#8221;<\/p><\/blockquote>\n<p>Distribution Groups:<br \/>\nCreate a new group:<br \/>\nNew-DistributionGroup -Name &#8220;<em>group name<\/em>&#8221; -Alias &#8220;<em>groupalias<\/em>&#8221; -OrganizationalUnit &#8216;<em>oudn<\/em>&#8216;<\/p>\n<p>Modify a group setting:<br \/>\nSet-DistributionGroup <em>groupalias<\/em> -RequireSenderAuthenticationEnabled $false<\/p>\n<p>Update a group member:<br \/>\nUpdate-DistributionGroupMember <em>groupalias<\/em> -Members &#8220;<em>emailaddress<\/em>&#8221;<\/p>\n<p>Add a group member:<br \/>\nAdd-DistributionGroupMember <em>groupalias<\/em> -Member &#8220;<em>emailaddress<\/em>&#8221;<\/p>\n<p>Remove a group member:<br \/>\nRemove-DistributionGroupMember <em>groupalias<\/em> -Member &#8220;<em>emailaddress<\/em>&#8221;<\/p>\n<p>Look at at distribution group:<br \/>\nGet-DistributionGroup <em>groupalias<\/em> | Format-List<\/p>\n<p>Get the list of members in a distribution group:<br \/>\nGet-DistributionGroupMember <em>groupalias<\/em> | Format-Table<\/p>\n<p>Check deleted item policy on a mailbox:<br \/>\nGet-Mailbox <em>alias<\/em> | Select Name,RetainDeletedItemsFor,RetainDeletedItemsUntilBackup<\/p>\n<p>How to find mailboxes that are hidden:<br \/>\nGet-Mailbox | where {$_.HiddenFromAddressListsEnabled -eq $true}<\/p>\n<p>This is a good command to list all options\/members of an object.  In this case a mailbox.  Get-Member can used like this against really any EMS command:<\/p>\n<p>Get-Mailbox | Get-Member<\/p>\n<p>To restore the deleted items, right mouse click on the &#8220;Deleted Items&#8221; folder and select &#8220;Recover Deleted Items.&#8221;  A window will come up with all the messages still available within the deleted item retention policy.<\/p>\n<p>To see if a mailbox has auditing enabled:<\/p>\n<blockquote><p>Get-Mailbox <em>mailboxname<\/em> | Select Name,AudtiEnabled<\/p><\/blockquote>\n<p>To enable auditing on a mailbox:<\/p>\n<blockquote><p>Set-Mailbox -Identity &#8220;<em>mailboxidentity<\/em>&#8221; -AuditEnabled $true<\/p><\/blockquote>\n<p>To search the audit log for activity in a mailbox:<\/p>\n<blockquote><p>Search-MailboxAuditlog -Identity &#8220;<em>mailboxidentity<\/em>&#8220;<\/p><\/blockquote>\n<p>Note: Enabling auditing seems to take a while before any results show up.<\/p>\n<p>An easy way to list all the folders and size in a mailbox:<br \/>\nGet-MailboxFolderStatistics -identity &#8220;myidentity&#8221;  | select FolderPath,FolderSize<\/p>\n<p>Here is a very good way to search through the logs using EMS:<br \/>\nGet-MessageTrackingLog -Start &#8220;mm\/dd\/yyyy HH:MM&#8221; -End &#8220;mm\/dd\/yyyy HH:MM&#8221;  -ResultSize Unlimited-Sender sender@email.address | Where {($_.Recipients -like &#8220;*somestring*&#8221;)}  | Select Sender,Recipients,TimeStamp,MessageSubject <\/p>\n","protected":false},"excerpt":{"rendered":"<p>To set a forwarding address for a mailbox that will also deliver the message to the Identity&#8217;s mailbox: Set-Mailbox -Identity identityname -DeliverToMailboxAndForward $true -ForwardingSMTPAddress &#8220;my@mail.address&#8220; Note: If DeliverToMailboxAndForward is $false, then the message will not be deliver to the Identity&#8217;s mailbox. Just forwarded. To remove a forwarding address for a mailbox: Set-Mailbox -Identity identityname -ForwardingSMTPAddress [&#038;hellip<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[336,358,125],"class_list":["post-1507","post","type-post","status-publish","format-standard","hentry","category-documentation","tag-commands","tag-ems","tag-exchange"],"share_on_mastodon":{"url":"","error":""},"_links":{"self":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/1507","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1507"}],"version-history":[{"count":27,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/1507\/revisions"}],"predecessor-version":[{"id":1904,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/1507\/revisions\/1904"}],"wp:attachment":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}