PS command to list users by office location

brichardi 311 Reputation points
2022-05-26T15:33:47.56+00:00

Hello PS guru,

I am trying to create a PS command to list users by office location. I tried different methods, but the command only list only location at a time.

For example, I want to list all users at office in "LA, SF,DC" but I think my syntax is incorrect and it only display one office city.

Thanks for your help.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,361 questions
{count} votes

Accepted answer
  1. Newbie Jones 1,306 Reputation points
    2022-05-26T16:59:56.383+00:00

    The principle will be the same for whatever command you use, or attributes you filter on.

    You need to filter using logical operators. AND\OR.

    For example...

    Get-CsOnlineUser -Filter {(AssignedPlan -eq 'Teams') -and (accountenabled -eq $True) -and ((UsageLocation -eq 'US') -or (UsageLocation -eq 'JP') -or (UsageLocation -eq 'UK'))} 
    
    Get-ADUser -properties physicalDeliveryOfficeName -Filter {(physicalDeliveryOfficeName -like "100*") -or (physicalDeliveryOfficeName -eq "Main Street")}
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. brichardi 311 Reputation points
    2022-05-26T18:11:37.59+00:00

    I tried using the operator "-and", "-or" and always got error "Error parsing query. I will try your command.

    Thanks

    0 comments No comments