Use array of strings for comparing in Where-Object in PowerShell Use array of strings for comparing in Where-Object in PowerShell powershell powershell

Use array of strings for comparing in Where-Object in PowerShell


You have several options:

$users | Where-Object {$Admin_User_Strings -contains $_.Description}

or: $users | Where-Object $_.Description -in $Admin_User_Strings

or: $users | Where-Object $_.Description -match "adm|admin|administrator"