[SOLVED] Removing text from... array?

Welcome Forums General PowerShell Q&A [SOLVED] Removing text from... array?

This topic contains 4 replies, has 3 voices, and was last updated by

 
Participant
4 years, 2 months ago.

  • Author
    Posts
  • #19210

    Participant
    Points: 42
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    This worked for me:

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

    Participant
    Points: 42
    Rank: Member

    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

    Participant
    Points: 53
    Rank: Member

    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.

  • #19221

    Participant
    Points: 42
    Rank: Member

    Mike F Robbins,

    Great! Worked perfectly.

    Thanks!

The topic ‘[SOLVED] Removing text from... array?’ is closed to new replies.