[SOLVED] Removing text from... array?


Beginner question…
I’m trying to do this:

$junked = Get-MailboxJunkEmailConfiguration $user |select BlockedSendersAndDomains -ExpandProperty BlockedSendersAndDomains




I want to remove the “user2@organization.com.br” from that variable so I can overwrite de junk rule doin’ something like this:

Set-MailboxJunkEmailConfiguration $user -BlockedSendersAndDomains $junked

The first command gives me an error saying that the collection has fixed size…

This worked for me:

$junked = Get-MailboxJunkEmailConfiguration $user
$junked.BlockedSendersAndDomains -= "user2@organization.com.br"
Set-MailboxJunkEmailConfiguration -Identity $user -BlockedSendersAndDomains $junked.BlockedSendersAndDomains

Ondrej Zilinec,

Thanks for replying.

But if there is more than one “@organization.com.br” record?
I wanted to get rid of all records from a specific domain.

Also, for me it isn’t working =/

PS C:\Office 365> $junked.BlockedSendersAndDomains -= "user2@organization.com.br"
Falha na invocação do método porque [System.Collections.ArrayList] não contém
um método denominado 'op_Subtraction'.
No linha:1 caractere:1
+ $junked.BlockedSendersAndDomains -= "user2@organization.com.br"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Subtraction:String) [], Ru
    + FullyQualifiedErrorId : MethodNotFound

Give this a shot:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
$user = 'username'
$junked = Get-MailboxJunkEmailConfiguration -Identity $user | Select-Object -ExpandProperty BlockedSendersAndDomains
$junked = $junked | Where-Object {$_ -notlike '*organization.com.br'}
Set-MailboxJunkEmailConfiguration -Identity $user -BlockedSendersAndDomains $junked

One thing to note is that the user must have logged into their email at least once or you’ll receive the following error message when trying to set their junk email configuration:

Set-MailboxJunkEmailConfiguration : The Junk Email configuration couldn’t be set. The user needs to sign in to Outlook Web App before they can modify their Safe Senders and Recipients or Blocked Senders lists.

Mike F Robbins,

Great! Worked perfectly.