question

brichardi avatar image
0 Votes"
brichardi asked brichardi answered

PS command to list users by office location

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
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You didn't post your code that you're using. Please post that along with how you tell what office a user is in. I assume it is based upon the OU of the AD account but I'm just guessing here.

0 Votes 0 ·
NewbieJones-6218 avatar image
0 Votes"
NewbieJones-6218 answered NewbieJones-6218 edited

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")}



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

brichardi avatar image
0 Votes"
brichardi answered

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

Thanks

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.