azure - 使用应用程序密码获取 AD 用户列表的方法

标签 azure powershell azure-active-directory

在应用程序中,我当前正在使用 PowerShell 和 MSOnline 模块(Connect-MsolService 和 Get-MsolUser)来获取 AD 用户列表。全局管理员提供他的用户名和密码,应用程序能够获取该租户下所有用户的列表。

效果很好...只要密码不是应用程序密码。使用应用程序密码时,全局管理员可以看到以下内容:

身份验证错误:用户名或密码错误

我的问题是:是否有任何其他方法,使用 PowerShell,但不一定要获取 AD 中的用户列表,但适用于应用程序密码?我了解 Graph API,但目前不适合该项目。

最佳答案

如果我理解正确的话,您想使用 AD 应用程序及其密码( secret )来列出用户。

您可以使用Az powershell 模块要执行此操作,请使用服务主体登录并通过 Get-AzADUser 列出用户。另外,请确保您的 AD 应用程序(服务主体)具有管理员角色,例如用户管理员全局管理员

$azureAplicationId ="<AD App Application id>"
$azureTenantId= "<tenant id>"
$azurePassword = ConvertTo-SecureString "<password>" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Connect-AzAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal

Get-AzADUser 

enter image description here

更新:

目前不支持使用启用MFA的用户的应用程序密码连接MSOL powershell,更多详细信息请参阅此link .

App passwords are NOT supported, simply use Connect-MsolService without any parameter to trigger the ADAL dialog and complete the 2FA challenge as normal.

关于azure - 使用应用程序密码获取 AD 用户列表的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57333003/

相关文章:

excel - 如何创建 Azure 文件存储文档的下载链接? PDF 有效,但 XLS 和 DOC 无效

azure - az acr 构建 dockerfile secret 声明

azure - 我可以在一个程序中使用具有不同订阅的多个事件中心吗?

windows - 列出具有文件大小的给定结构中的所有文件夹和子文件夹

azure - 无法访问 AAD 中的用户/组

azure - Azure AD b2c 中的自定义策略 - 声明提供程序指南的问题

azure kql 从 VMSS 获取 OSversion 和 OSName

powershell - 在 Powershell 中没有换行符的写入输出?

powershell - PowerShell 中的 OAuth2.0 授权代码流

java - 无法检索远程 JWK 集 : login. microsoftonline.com