Operator "contains" not working as expected

Welcome Forums General PowerShell Q&A Operator "contains" not working as expected

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

 
Moderator
3 weeks, 2 days ago.

  • Author
    Posts
  • #146454

    Participant
    Points: 16
    Rank: Member

    I have two arrays one is having DLs current membership details  $DL = @() and another one is having all Users Profile Data from Okta which i get it by API call $okta().

    $DL = @()

    $okta = @()

    $Okta | ForEach { if (($_.Manager -eq "XYZ") -and ($DL.PrimarySMTP -notcontains $_.email) )
    {$NewMember += @($_)}
    }

    I get don't get new member details in $NewMember but i get details who are already in the DL. can anyone help me with this

     

    Thank you

     

  • #146529

    Moderator
    Points: 1,981
    Helping Hand
    Rank: Community Hero

    Few missing pieces.

    The $DL variable yo provided is empty. Hence property 'PrimarySMTP' cannot be used. Variable $okta is also empty.
    I believe DL variable will have list of mail IDs. But difficult to guess. Pleas share the values(sample) if possible.

    • #146843

      Participant
      Points: 16
      Rank: Member

      You can assume something like this

      $DL = @()

      $DL = Get-DistributionGroupMember "some-DL" -ResultSize unlimited

      $okta = @()  # let's assume it has User data which we got it from Okta API using invoke-restmethod commandlets

      It has user profile like first name last name and email id etc

      basically i am querying this metadata for new hire joining to some manager's team and same time I am validating that if user is already in the DL

      unfortunately  I am not getting new user who is in the $okta but not in the DL

      Hope this is clear

    • #146850

      Participant
      Points: 28
      Rank: Member

      HI rpsingh

      while querying $_.Manager -eq "XYZ" can you validate the value XYZ seems problem with there, as you used the equal operator(-eq) it needs to be the exact match or else you can try with -like operator,unless all other values present correctly.

  • #146961

    Moderator
    Points: 1,981
    Helping Hand
    Rank: Community Hero

    I suggest you to use an editor (VSCode or PowerShell ISE), save this code as script and put a break point on if condition and debug. THis will give you the reason for unexpected behavior. You can share the results here.

You must be logged in to reply to this topic.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort