Using Get-MgUser to query on multiple -Search criteria

Mongoose 36 Reputation points
2024-05-01T18:20:23.29+00:00

I am attempting to replicate a Get-AzureADUser command using Get-MgUser. The previous command (Get-AzureADUser -Top 5000 | Where-Object {($.AccountEnabled -eq "True") -and (($.CompanyName -eq "CompA" -or $.CompanyName -eq "CompB" -or $.CompanyName -eq "CompC" -or $_.CompanyName -eq "CompD"))} | Select UserPrincipalName) selected the desired accounts. I have gotten this far with the replacement: Get-MgUser -All -Filter "AccountEnabled eq true" -Search "CompanyName:CompA" -ConsistencyLevel: eventual | Select UserPrincipalName

I have been unsuccessful in adding more search options for the CompanyName field. How do I use the -Search option to search for multiple values?

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,118 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Mongoose 36 Reputation points
    2024-05-01T19:38:54.68+00:00

    I found another related question. Why does 'Get-AzureADUser -ObjectID User@domain.net' display data for MailNickname but 'Get-MgUser -UserID User@domain.net' shows the field as blank? Should I pose this as a separate question?

    0 comments No comments