-OR condition not working in IF statement

The script only seems to be working if the first condition is met. It is not working if the User2 is met.  ($Session.Username -ne "user2") Is there some reason why the -OR isn't working in the IF statement. Any ideas?

function onGetEffectivePolicy($Request)
{
$Session = $Security.Sessions.Current
$UserName = $Session.UserName

if (($Session.UserName -ne "User1") -OR ($Session.UserName -ne "User2" ))
 
   { Import-Module "C:\ARS\ARSCmdlets.dll" -Force
           
        $testTitlesNoOwner = Get-SsoInfo TitleWithoutOwner  
        $testTitlesNoOwner

      $Request.SetEffectivePolicyInfo('title', $Constants.EDS_EPI_UI_RESTRICTED, $true)
        $Request.SetEffectivePolicyInfo('title', $Constants.EDS_EPI_UI_POSSIBLE_VALUES, [string[]]$testTitlesNoOwner)
}

else

 { Import-Module "C:\ARS\ARSCmdlets.dll" -Force
              
         $testTitlesOwner = Get-SsoInfo Title
         $testTitlesOwner
    
        $Request.SetEffectivePolicyInfo('title', $Constants.EDS_EPI_UI_RESTRICTED, $true)
        $Request.SetEffectivePolicyInfo('title', $Constants.EDS_EPI_UI_POSSIBLE_VALUES, [string[]]$testTitlesOwner)
   
}
}

Parents
  • Hi there,

    In this IF statement, it's best to give a sample value to understand what's happening.

    Let's make the username "User1".

    The first statement gets skipped because it is equal to "User1". The second statement will catch it to be TRUE and run code block.

    Let's make the username "User2".

    The first statement will catch it to be TRUE and the code block will run.

    Let's make the username "User3".

    Both statements will catch it to be TRUE and the code block will run.

    So you can see that no matter what the username is, the code block will run. You'll want to set it as -AND to make sure that it only runs when the username is NEITHER "User1" nor "User2".

Reply
  • Hi there,

    In this IF statement, it's best to give a sample value to understand what's happening.

    Let's make the username "User1".

    The first statement gets skipped because it is equal to "User1". The second statement will catch it to be TRUE and run code block.

    Let's make the username "User2".

    The first statement will catch it to be TRUE and the code block will run.

    Let's make the username "User3".

    Both statements will catch it to be TRUE and the code block will run.

    So you can see that no matter what the username is, the code block will run. You'll want to set it as -AND to make sure that it only runs when the username is NEITHER "User1" nor "User2".

Children
No Data