Create Azure AD B2C local account user with Powershell New-A



我正在尝试在 Azure AD B2C 目录中创建一个本地用户,该用户可以在创建后立即用于身份验证。

Connect-AzureAD -TenantId $targetB2cTenant
$passwordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile
$passwordProfile.Password = "Test-User-Password-Here"
$userName = "TestUser@MyTestB2CTenant.onmicrosoft.com"    
$signInNames = @(
    (New-Object `
        Microsoft.Open.AzureAD.Model.SignInName `
        -Property @{Type = "userName"; Value = $userName})
)
$newUser = New-AzureADUser -AccountEnabled $True -DisplayName "testpowershellusercreation" -PasswordProfile $passwordProfile -SignInNames $signInNames -CreationType "LocalAccount"
Disconnect-AzureAD

通过阅读文档,我需要将 CreationType 参数指定为"LocalAccount":

https://learn.microsoft.com/en-us/powershell/module/azuread/new-azureaduser?view=azureadps-2.0

使用可立即登录的 MFA 创建 B2C 用户

但是,当我运行Powershell代码时,我收到以下错误:

New-AzureADUser : Error occurred while executing NewUser 
Code: Request_BadRequest
Message: One or more properties contains invalid values.

当我删除 -CreationType 参数时,此错误消息不存在。

使用 Powershell 在 B2C 目录中创建本地帐户的正确方法是什么?

类型为"userName"的登录名不能在 value 属性中包含"@"字符。

即您不能将其设置为电子邮件地址。

您可能还希望为新用户设置以下参数:

$passwordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile
$passwordProfile.ForceChangePasswordNextLogin = $False
$passwordProfile.Password = "<Password>"
$newUser = New-AzureADUser ... -PasswordPolicies "DisablePasswordExpiration"
我认为

您还可以将登录名的类型从"用户名"更改为"电子邮件",以解决此问题,并允许用户继续使用其外国域电子邮件地址作为登录名(如果需要(。

$signInNames = (
    (New-Object `
        Microsoft.Open.AzureAD.Model.SignInName `
        -Property @{Type = "email"; Value = "pstesta@fsdfsd.com"})
)

最新更新