提问人:Tuwan J 提问时间:9/24/2023 最后编辑:Tuwan J 更新时间:10/27/2023 访问量:240
MSOnline #Powershell
MSOnline #Powershell
问:
**当我运行这个脚本时**
$Uppn = "[email protected]"`
$UserID = "00000"
$DisName = "XXX XXXX "
$FirstNm = "XXXX "
$LastNm = "XXXX "
$AltEmail = "[email protected]"
$Mobilenum = "+11111111111"
New-MsolUser -UserPrincipalName $Uppn -ImmutableId $UserID -DisplayName $DisName -FirstName $FirstNm -LastName $LastNm -AlternateEmailAddresses $AltEmail -LicenseAssignment "aaa:STANDARDWOFFPACK_STUDENT" -UsageLocation "LK" -MobilePhone $Mobilenum`
我收到这个问题
New-MsolUser : Unknown error occurred.
At line:1 char:1
+ New-MsolUser -UserPrincipalName $Uppn -ImmutableId $UserID -DisplayNa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) \[New-MsolUser\], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.OperationNotAllowedException,Microsoft.Online.Administration.Automation.NewUser`
有什么解决方案吗?
我尝试了不同的方法,cmdlet,Microsoft Graph PowerShell。我没有得到任何好的结果:(
答:
1赞
Re1ter
9/24/2023
#1
cmdlet New-MsolUser 的 cmdlet Set-MsolUserLicense 和参数 -LicenseAssignment 已弃用。尝试使用 Microsoft Graph PowerShell SDK。
可以使用此包中的命令 New-MgUser 创建新用户的示例可以在此处查看。它应该看起来像这样:
Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All
$PasswordProfile = @{
Password = 'xWwvJ]6NMw+bWH-d'
}
New-MgUser -DisplayName 'Rene Magritte' -PasswordProfile $PasswordProfile -AccountEnabled -MailNickName 'ReneMagritte' -UserPrincipalName '[email protected]'
$UserId = (Get-MgUser -ConsistencyLevel eventual -Count userCount -Filter "startsWith(DisplayName, 'Rene Magi')").Id
$EmsSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'aaa:STANDARDWOFFPACK_STUDENT'
Set-MgUserLicense -UserId $UserId -AddLicenses @{SkuId = $EmsSku.SkuId} -RemoveLicenses @()
评论