locked
Comparison Help RRS feed

  • Question

  • Hello, I believe I am having trouble figuring out how to find if a value exists in a multiple value property (new to PS scripting). In my first if statement, I am trying to perform an action on any DL that doesn't have "test01" in the AcceptMessagesOnlyFromSendersOrMembers, but seems like it's only looking at the first value. Any ideas?

    $DLmods = Get-DistributionGroup *test* | Where-Object {$_.AcceptMessagesOnlyFromSendersOrMembers -ne $null}
    
    foreach ($DLmod in $DLmods)
    {   
      if ($DLmod.AcceptMessagesOnlyFromSendersOrMembers -notmatches "test01")
      {     
        Set-DistributionGroup -Identity $DLmod.name -AcceptMessagesOnlyFromSendersOrMembers @{Add="test01"};
      }
      elseif ($DLmod.AcceptMessagesOnlyFromSendersOrMembers)
      {
        Get-DistributionGroup $DLmod.name;
      }
      else
      {
        Write-Output $DLmod.name
        Write-Output "Error";
      }
    }


    • Edited by riz0x Monday, October 22, 2018 3:31 AM
    Monday, October 22, 2018 3:29 AM

Answers

  • You have ti use the whole DL name not just part of it.


    \_(ツ)_/

    • Marked as answer by riz0x Monday, October 22, 2018 4:41 AM
    Monday, October 22, 2018 4:25 AM

All replies

  • Only "contains" or "notcontains" works with a collection.

    $DLmod.AcceptMessagesOnlyFromSendersOrMembers -notcontains 'test01'


    \_(ツ)_/

    Monday, October 22, 2018 3:58 AM
  • You're right. Unfortunately, when I run that operator manually, I am getting inaccurate results. I ran:

    Get-DistributionGroup *test* | where {$_.AcceptMessagesOnlyFromSendersOrMembers -notcontains "test01"}

    I am getting DLs that do have "test01" listed in the property. 


    Monday, October 22, 2018 4:10 AM
  • You have ti use the whole DL name not just part of it.


    \_(ツ)_/

    • Marked as answer by riz0x Monday, October 22, 2018 4:41 AM
    Monday, October 22, 2018 4:25 AM
  • That was the problem! Thank you very much.
    Monday, October 22, 2018 4:41 AM