MSOnline #Powershell

sqougxex  于 2023-11-18  发布在  Shell
关注(0)|答案(1)|浏览(118)

当我运行此脚本

$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`


有什么办法吗?
我尝试了不同的方法,小工具,Microsoft Graph PowerShell.我没有得到任何好的结果:(

zf9nrax1

zf9nrax11#

不推荐使用RolletNew-MsolUser的RolletSet-MsolUserLicense和参数**-LicenseAssignment**。请尝试使用Microsoft Graph PowerShell SDK
here中可以看到一个使用命令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 @()

字符串

相关问题