MSOnline #Powershell

**When I run this script **

    $Uppn = "XXX@ms.XX.XX"`
    $UserID = "00000"
    $DisName = "XXX XXXX "
    $FirstNm = "XXXX "
    $LastNm = "XXXX "
    $AltEmail = "xxxxxxx@xx.xx.xx.x"
    $Mobilenum = "+11111111111"
    New-MsolUser -UserPrincipalName $Uppn -ImmutableId $UserID -DisplayName $DisName -FirstName      $FirstNm -LastName $LastNm -AlternateEmailAddresses $AltEmail -LicenseAssignment   "aaa:STANDARDWOFFPACK_STUDENT" -UsageLocation "LK" -MobilePhone $Mobilenum`

I get this issue

    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`

Any solutions?

i tried with different methods, cmdlet, Microsoft Graph PowerShell. I didn't get any good outcome :(


  • The cmdlet Set-MsolUserLicense and parameter -LicenseAssignment of cmdlet New-MsolUser are deprecated. Try using Microsoft Graph PowerShell SDK.

    An example of creating a new user with command New-MgUser from this package can be seen here. It should look something like this:

    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 ''
    $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 @()