Powershell If with -or Operator

Powershell If with -or Operator

Is the following syntax correct because the code is not skipping as it should.

foreach($acc in get-SPmanagedAccount)
{
    $accNamewithDomain = $acc.UserName
    $accname = $accNamewithDomain.Split("\")[1] 

    if(($accName -ne "svc-reader-tst") -or ($accName -ne "svc-writer-tst"))
    {
       # do somthing
    }
}
4

1 Answer

I updated the code with -and operator per Arnavion and it's working as expected.

foreach($acc in get-SPmanagedAccount)
{
    $accNamewithDomain = $acc.UserName
    $accname = $accNamewithDomain.Split("\")[1] 

    if(($accName -ne "svc-reader-tst") -and ($accName -ne "svc-writer-tst"))
    {
       # do somthing
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.