在应用程序中,我当前正在使用 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
更新:
目前不支持使用启用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/