Powershell new user issue

Kareem 85 Reputation points
2024-04-25T19:29:22.9933333+00:00

Hello. I am currently trying to learn the basics of using Powershell with Office365 and one of those is creating a new user. I enter the below code as a test:

new-msoluser -UserPrincipalName "HYang@mirador.com" -DisplayName "Harp Yan" -Firstname "Harp" -LastName "Yan" -UsageLocation "IN" -LicenseAssignment "my license"

After typing the command, I get the error below:

WARNING: This licensing cmdlet has been retired. Please update to MS Graph Set-MgUserLicense: https://aka.ms/mguserlicense

I don't really understand what that means and how I can work around this. The videos I am watching are currently two years old so I would like to know if Powershell coding has changed. Any help would be appreciated. Thank you.

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
3,836 questions
Office
Office
A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.
1,317 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,647 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,081 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Marcin Policht 11,385 Reputation points MVP
    2024-04-25T19:43:55.2066667+00:00

    This means that you should not be using the PowerShell cmdlets that include "msol" in their name (following the "-" character).

    Instead, you should be using cmdlets which include "mg" in their name (following the "-" character).

    To create a user, follow https://learn.microsoft.com/en-us/microsoft-365/enterprise/create-user-accounts-with-microsoft-365-powershell?view=o365-worldwide

    To set a license, follow https://learn.microsoft.com/en-us/microsoft-365/enterprise/assign-licenses-to-user-accounts-with-microsoft-365-powershell?view=o365-worldwide


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin


  2. Kareem 85 Reputation points
    2024-04-25T20:21:57.8066667+00:00

    Thanks for the response. When I type "Connect-MgGraph -Scopes "User.ReadWrite.All" in Powershell, I get an error saying that "Connect-MgGraph" is not recognized as the name of a cmdlet.