Sql server 我们可以从sql server用户表将用户导入Azure AD吗

Sql server 我们可以从sql server用户表将用户导入Azure AD吗,sql-server,azure-active-directory,Sql Server,Azure Active Directory,我们有.net应用程序,每个应用程序都有自己的用户表(其中一些是AspNetUsers表)。现在我们考虑使用Azure Active Directory作为进行身份验证和授权的中心位置。有没有办法将用户从现有的sql server用户表导入Azure AD?我似乎没有找到这样的方法,我所看到的只是一些来自本地广告的重要信息。使用AAD Graph API或AAD PowerShell,您可以通过编程方式在租户中创建新用户 对于: 您可以在上找到跨多种语言访问AAD Graph API的示例 用于

我们有.net应用程序,每个应用程序都有自己的用户表(其中一些是AspNetUsers表)。现在我们考虑使用Azure Active Directory作为进行身份验证和授权的中心位置。有没有办法将用户从现有的sql server用户表导入Azure AD?我似乎没有找到这样的方法,我所看到的只是一些来自本地广告的重要信息。

使用AAD Graph API或AAD PowerShell,您可以通过编程方式在租户中创建新用户

对于:

您可以在上找到跨多种语言访问AAD Graph API的示例

用于:


让我知道这是否有用。

如果您还没有这样做,SQL中的查询结果可以保存到CSV。然后使用PowerShell导入Azure。需要注意的是,您需要一个AAD帐户来完成导入部分。由于Azure AD的PowerShell模块很挑剔,您应该通过执行以下操作来更新PowerShell

PS C:\> Install-Module -Name AzureADPreview -RequiredVersion 2.0.2.5 -Verbose -Force
转到此页面以获取最新版本信息。(从这个网站下载对我来说不起作用,但是,运行上面的脚本确实起作用

更新后,使用以下脚本导入文件

$Credential = Get-Credential
Connect-AzureRmAccount -Credential $Credential -Tenant "xxxx-xxxx-xxxx-xxxx" -ServicePrincipal
Account: AzureUser@contosso.onmicrosoft.com
Environment: AzureCloud #usually the region your AAD is located, such as CentralUS.
Subscription: yyyy-yyyy-yyyy-yyyy
Tenant: xxxx-xxxx-xxxx-xxxx

$SecureStringPassword = ConvertTo-SecureString -String "ComplexPasswordString" -AsPlainText -Force
$Users = Import-Csv 'C:\Path to CSV file\SQL_USER_FILE.csv'
$Users | ForEach-Object { 
New-AzureRmADUser -DisplayName $_.DisplayName -UserPrincipalName $_.UserPrincipalName -Password $SecureStringPassword -MailNickname $_.MailNickName -Verbose
 }
如果由于登录而无法正常工作,则可以使用更简化的版本,但需要您使用AAD帐户登录

Connect-AzureRMAccount
$SecureStringPassword = ConvertTo-SecureString -String "ComplexPasswordString" -AsPlainText -Force
$Users = Import-Csv 'C:\Path to CSV file\SQL_USER_FILE.csv'
$Users | ForEach-Object { 
New-AzureRmADUser -DisplayName $_.DisplayName -UserPrincipalName $_.UserPrincipalName -Password $SecureStringPassword -MailNickname $_.MailNickName -Verbose
 }
I User-Verbose为我提供导入的运行状态。如果没有它,执行是无声的。哦,在千兆连接上执行1500个用户大约需要15分钟。Tp告诉您需要多长时间

有关自动登录的详细信息,请参见此处。

警告
CSV必须具有上面所示的必需字段。因此,您可能需要进行一些欺骗以使它们匹配。只需知道唯一真正重要的字段是-UserPrincipalName=user@contosso.onmicrosoft.com.

您想对用户密码做什么?是否可以为您生成密码,然后更改以购买用户?是,我们可以要求客户这样做。因此,现有密码(它们在表中散列)不能再使用了?我的意思是,它们可以在AAD中重复使用,但你不可能简单地将哈希复制到AAD,你也不应该真的能够…如果你能得到密码的未修改版本,我下面的答案允许你显式设置密码。附录:这个脚本的问题是它只添加了用户。你会d需要执行另一个PowerShell脚本来为组和应用程序分配成员身份。您可能可以使用-Password$\运行此脚本。“Password”。我尚未测试它。
$Credential = Get-Credential
Connect-AzureRmAccount -Credential $Credential -Tenant "xxxx-xxxx-xxxx-xxxx" -ServicePrincipal
Account: AzureUser@contosso.onmicrosoft.com
Environment: AzureCloud #usually the region your AAD is located, such as CentralUS.
Subscription: yyyy-yyyy-yyyy-yyyy
Tenant: xxxx-xxxx-xxxx-xxxx

$SecureStringPassword = ConvertTo-SecureString -String "ComplexPasswordString" -AsPlainText -Force
$Users = Import-Csv 'C:\Path to CSV file\SQL_USER_FILE.csv'
$Users | ForEach-Object { 
New-AzureRmADUser -DisplayName $_.DisplayName -UserPrincipalName $_.UserPrincipalName -Password $SecureStringPassword -MailNickname $_.MailNickName -Verbose
 }
Connect-AzureRMAccount
$SecureStringPassword = ConvertTo-SecureString -String "ComplexPasswordString" -AsPlainText -Force
$Users = Import-Csv 'C:\Path to CSV file\SQL_USER_FILE.csv'
$Users | ForEach-Object { 
New-AzureRmADUser -DisplayName $_.DisplayName -UserPrincipalName $_.UserPrincipalName -Password $SecureStringPassword -MailNickname $_.MailNickName -Verbose
 }