[SOLVED] Removing text from... array?

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Vandrey Trindade Vandrey Trindade 2 years, 2 months ago.

  • Author
    Posts
  • #19210
    Profile photo of Vandrey Trindade
    Vandrey Trindade
    Participant

    Hi,

    Beginner question...
    I'm trying to do this:

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

    So:

    $junked

    user@ymail.com
    user1@gmail.com
    user2@organization.com.br
    yahoo@yahoo.com

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

    $junked.Remove("*organization.com.br")
    Set-MailboxJunkEmailConfiguration $user -BlockedSendersAndDomains $junked

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

  • #19212
    Profile photo of Ondrej Zilinec
    Ondrej Zilinec
    Participant

    This worked for me:

    $junked = Get-MailboxJunkEmailConfiguration $user
    $junked.BlockedSendersAndDomains -= "user2@organization.com.br"
    Set-MailboxJunkEmailConfiguration -Identity $user -BlockedSendersAndDomains $junked.BlockedSendersAndDomains
    
  • #19215
    Profile photo of Vandrey Trindade
    Vandrey Trindade
    Participant

    Ondrej Zilinec,

    Thanks for replying.
    Nice!

    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
       ntimeException
        + FullyQualifiedErrorId : MethodNotFound
  • #19216
    Profile photo of Mike F Robbins
    Mike F Robbins
    Participant

    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:

    [i]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.[/i]

  • #19221
    Profile photo of Vandrey Trindade
    Vandrey Trindade
    Participant

    Mike F Robbins,

    Great! Worked perfectly.

    Thanks!

You must be logged in to reply to this topic.