azure - Get-AzADUser 按邮件字段中的域进行过滤

标签 azure powershell azure-active-directory

我正在尝试执行可以对 Azure AD 进行查询的 PowerShell 命令行。 我们的 AD 中有数百名(数千名)用户有来自不同域的邮件。

我尝试使用

Get-AzADUser -Filter "endsWith(Mail,'somedomain.com')"

但是过滤子句 endsWith 不适用于 -Filter。

还尝试使用 -SearchString 但不适用于邮件列/值。

我想避免使用“where”管道进行一般查询来进行过滤,因为处理时间太长。

最佳答案

它可以工作,但您需要在调用中使用 -ConsistencyLevel Eventual-Count:

  • 使用 Az 模块:
Get-AzADUser -Filter "endsWith(Mail, 'somedomain.com')" -ConsistencyLevel Eventual -Count
  • 使用 Microsoft.Graph 模块:
Select-MgProfile beta
Get-MgUser -Filter "endsWith(Mail, 'somedomain.com')" -ConsistencyLevel Eventual -CountVariable count -All

如果要查询users API直接,您可以使用 Invoke-RestMethod 但此技术要求您处理 pagination手动:

$req = @{
    Uri     = "https://graph.microsoft.com/beta/users?`$filter=endsWith(mail, 'somedomain.com')&`$count=true"
    Headers = @{
        Authorization    = 'Bearer {0}' -f (Get-AzAccessToken -ResourceUrl https://graph.microsoft.com).Token
        ConsistencyLevel = 'Eventual'
    }
}
$response = Invoke-RestMethod @req

关于azure - Get-AzADUser 按邮件字段中的域进行过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76111960/

相关文章:

Azure 辅助存储 (RAGRS)

c# - Azure 网站 : how to establish a socket connection on loopback interface?

powershell - 如何在 Windows 10 中退出时重新启动 exe?

string - 通过 Powershell 进行日志解析 - 打印第 n 个元素之后的所有数组元素

python - 获取主板上内存插槽总数的方法

azure-active-directory - keycloak 如何设置来自外部身份提供商的用户信息

Azure Graph API 邀请返回 400 错误请求

function - MSBuild 在发布前执行 OctoPack

Azure 事件目录 | Multi-Tenancy 应用

azure - 通过 ARM 模板更新弹性池 EDTU