Powershell

Usefull powershell command or scripts

Exchange | SCOM

Get all mailboxes that have an email address that is like ”domain.com” and if the mailbox has a forward set what address is it being forwarded to.

get-mailbox -filter "emailaddresses -like '*@domain.com'" |select-object displayName,SmtpAddress,@{n='ContactEmail';e={(Get-Contact $_.ForwardingAddress).WindowsEmailAddress.ToString()}}| Export-Csv forwards.csv –notypeinformation

Get mailboxstatistics from all members in a specific domain

get-mailbox -resultsize unlimited |where {$_.PrimarySmtpAddress -like "*domain.com"}|Get-MailboxStatistics |sort TotalItemSize -Descending|ft DisplayName,@{label="Total Size (MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount -auto

Remove specific email from ALL mailboxes in Exchange 2010 SP1. Use the Shell to search for messages and log the search results: Link

Get-Mailbox -Server  "*Server*" | Search-Mailbox -SearchQuery 'Subject:"*Subject*" and Body:"*Body*"' -targetmailbox "*SearchMailbox*" -targetfolder "*SearchFolder*" -logonly -loglevel full

  • Delete all emails that meet the search query
    1 Get-Mailbox -Server  "*Server*" | Search-Mailbox -SearchQuery 'Subject:"*Subject*" and Body:"*Body*"' -deletecontent
  • Copy all emails to a single mailbox, then delete the emails
    1 Get-Mailbox -Server  "*Server*" | Search-Mailbox -SearchQuery 'Subject:"*Subject*" and Body:"*Body*"' -targetmailbox "*SearchMailbox*" -targetfolder "*SearchFolder*" -loglevel full -deletecontent

==================

https://jamiemckillop.wordpress.com/category/reporting/

ActiveSync Power Administrator

WizBang Exchange Message Tracker 2.0

==================

Set a targetaddress

Set-ADUSer $_.users -Replace @{targetAddress=”$tmail”}}

 

Resubmit all messages located in the Unreachable queue

Retry-Queue -Identity "<ServerName>\Unreachable" -Resubmit $true

====================

One of Exchange Online functionalities as part of the Office365 suite is the ability to forward mails to another mailbox or smtp address quick and easy using the users Office365 portal. Besides, what happens when you have to do it as an admin on 500 users at a time? it results tedious right?.

Well, we can do this quickly with the help of PowerShell with the following commands:

Forward mails to another mailbox:

Set-Mailbox user@domain.com -ForwardingAddress dest_mailbox@domain.com

Forward mailbox without saving a local copy:

Set-Mailbox user@domain.com -ForwardingAddress dest_mailbox@domain.com -DeliverToMailboxAndForward $false

Forwarding mails to another external mailbox:

Set-Mailbox user@domain.com -ForwardingSmtpAddress ext_mailbox@domain.com

Forwarding mails to another external mailbox without saving a local copy:

Set-Mailbox user@domain.com -ForwardingSmtpAddress ext_mailbox@domain.com -DeliverToMailboxAndForward $false

Apply the forwarding to users in mass:

Get-Mailbox | Where {$_.RecipientType -eq “UserMailbox”} | Set-Mailbox -ForwardingAddress dest_mailbox@domain.com

Apply the forwarding to users to be sent to external users in mass:

Get-Mailbox | Where {$_.RecipientType -eq “UserMailbox”} | Set-Mailbox -ForwardingSmtpAddress ext_mailbox@domain.com

Get forwarding Info of a user:

Get-Mailbox -Identity user@domain.com | fl DeliverToMailboxAndForward, ForwardingAddress, ForwardingSmtpAddress

Remove mail forwarding:

Set-Mailbox user@domain.com -ForwardingAddress $null

Remove mail forwarding sent to an external user:

Set-Mailbox user@domain.com -ForwardingSmtpAddress $null

Remove mail forwarding to users in mass:

Get-Mailbox | Where {$_.RecipientType -eq “UserMailbox”} | Set-Mailbox -ForwardingAddress $null

Remove mail forwarding sent to external users to users in mass:

Get-Mailbox | Where {$_.RecipientType -eq “UserMailbox”} | Set-Mailbox -ForwardingSmtpAddress $null

Leave a Reply

You must be logged in to post a comment.