You can use the (Set|Get)-MailboxJunkEmailConfiguration
cmdlets to set or view the Junk Email configuration of a mailbox. For instance:
1 2 3 4 5 6 7 8 9 10 11 12 |
PS> Get-MailboxJunkEmailConfiguration rakhesh RunspaceId : 0368e0cf-2479-41e2-b9b6-b3ee25d00faf Enabled : True TrustedListsOnly : False ContactsTrusted : True TrustedSendersAndDomains : {example.com} BlockedSendersAndDomains : {} MailboxOwnerId : rakhesh.com/Users/Sasidharan, Rakhesh Identity : rakhesh.com/Users/Sasidharan, Rakhesh IsValid : True |
From the Get-MailboxJunkEmailConfiguration
output above I can see Junk Email configuration is Enabled for this mailbox, all email addresses in the Contacts folder of this mailbox are automatically added to the trusted senders list, any emails from the example.com domain are considered trusted senders and delivered to the mailbox, and no domain is considered blocked and hence not delivered to mailbox. Further, the mailbox is not solely relying on these trusted lists – if it were, then only addresses in the trusted list would be allowed through and everything else discarded.
To change these values use the Set-MailboxJunkEmailConfiguration
cmdlet. Its syntax is pretty straightforward.
To add entries to the trusted or blocked senders lists one must retrieve the entries first and then append to it. So either do it the longish way like this:
1 2 3 |
PS> $temp = (Get-MailboxJunkEmailConfiguration rakhesh).TrustedSendersAndDomains PS> $temp += "blah.com","blah2.com" PS> Set-MailboxJunkEmailConfiguration rakhesh -TrustedSendersAndDomains $temp |
Or do it all in one go like this:
1 |
PS> Set-MailboxJunkEmailConfiguration rakhesh -TrustedSendersAndDomains ((Get-MailboxJunkEmailConfiguration rakhesh).TrustedSendersAndDomains + "blah.com" + "blah2.com") |
In either case the result is the same:
1 2 3 4 5 6 7 8 9 10 11 12 |
PS> Get-MailboxJunkEmailConfiguration rakhesh RunspaceId : 0368e0cf-2479-41e2-b9b6-b3ee25d00faf Enabled : True TrustedListsOnly : False ContactsTrusted : True TrustedSendersAndDomains : {example.com, blah.com, blah2.com} BlockedSendersAndDomains : {} MailboxOwnerId : rakhesh.com/Users/Sasidharan, Rakhesh Identity : rakhesh.com/Users/Sasidharan, Rakhesh IsValid : True |
Of course, goes without saying, the beauty of being able to do something like this via PowerShell rather than manually on Outlook or Outlook Web App is that you can do bulk action. Like for instance:
1 2 3 4 5 6 7 |
PS> Get-Recipient -OrganizationalUnit rakhesh.com/Planet/Mars/Users | Get-MailboxJunkEmailConfiguration | ft Identity,Enabled,TrustedListsOnly,ContactsTrusted -AutoSize Identity Enabled TrustedListsOnly ContactsTrusted -------- ------- ---------------- --------------- rakhesh.com/Planet/Mars/Alien1 True False True rakhesh.com/Planet/Mars/Alien2 True False False rakhesh.com/Planet/Mars/Alien3 True False True |
Easy to see at one shot what the status for each user is.
1 2 3 4 5 6 7 8 9 |
PS> Get-Recipient -OrganizationalUnit rakhesh.com/Planet/Mars/Users | Get-MailboxJunkEmailConfiguration | ft Identity,TrustedSendersAndDomains,BlockedSendersAndDomains -AutoSize WARNING: column "BlockedSendersAndDomains" does not fit into the display and was removed. Identity TrustedSendersAndDomains -------- ------------------------ rakhesh.com/Planet/Mars/Alien1 {} rakhesh.com/Planet/Mars/Alien2 {rsvp@omansail.com} rakhesh.com/Planet/Mars/Alien3 {} |
I can get rid of the OU name in the Identity column via some format-table
regexpery.
1 2 3 4 5 6 7 8 9 |
PS> Get-Recipient -OrganizationalUnit rakhesh.com/Planet/Mars/Users | Get-MailboxJunkEmailConfiguration | ft @{Name="Identity"; Expression={ $_.Identity -replace ".+/(.+)",'$1' } },TrustedSendersAndDomains,BlockedSendersAndDomains WARNING: column "BlockedSendersAndDomains" does not fit into the display and was removed. Identity TrustedSendersAndDomains -------- ------------------------ Alien1 {} Alien2 {rsvp@omansail.com} Alien3 {} |
A variation of the above:
1 2 3 4 5 6 7 |
PS> Get-Recipient -OrganizationalUnit rakhesh.com/Planet/Mars/Users | Get-MailboxJunkEmailConfiguration | ft @{Name="Identity"; Expression={ $_.Identity -replace "(.+?/){2}(.+)",'$2' } },TrustedSendersAndDomains,BlockedSendersAndDomains Identity TrustedSendersAndDomains -------- ------------------------ Mars/Alien1 {} Mars/Alien2 {rsvp@omansail.com} Mars/Alien3 {} |
Here I am using regexp to strip out the “rakhesh.com/Planet” bit so I only get the user identity and the OU it is in. I do this by making the +
regexp operator non greedy so it doesn’t match all the input text – rather, it stops at the first “/” character. I then put this regexp in brackets to club it together and tell PowerShell to match exactly two instances of this (hence the {2}
) so what remains is the bit which I want. Regexps are great when they work and you can make sense of them!