User management is a fundamental task in any Microsoft 365 environment, and Microsoft Graph PowerShell provides the cmdlets to manage them through PowerShell.
The New-MgUser cmdlet in PowerShell creates a new user in Microsoft Graph.
To use the New-MgUser cmdlet, you must first connect to your Microsoft 365 tenant using the Connect-MGraph
cmdlet. Once you are connected, you can use the New-MgUser cmdlet to create a new user.
Connect-MgGraph -Scopes User.ReadWrite.All
The syntax to create a new user object is given below.
New-MgUser
[-AboutMe <String>]
[-AccountEnabled]
[-Activities <IMicrosoftGraphUserActivity[]>]
[-AdditionalProperties <Hashtable>]
[-AgeGroup <String>]
[-AgreementAcceptances <IMicrosoftGraphAgreementAcceptance[]>]
[-AppRoleAssignments <IMicrosoftGraphAppRoleAssignment[]>]
[-AssignedLicenses <IMicrosoftGraphAssignedLicense[]>]
[-AssignedPlans <IMicrosoftGraphAssignedPlan[]>]
[-Authentication <IMicrosoftGraphAuthentication>]
[-AuthorizationInfo <IMicrosoftGraphAuthorizationInfo>]
[-Birthday <DateTime>]
[-BusinessPhones <String[]>]
[-Calendar <IMicrosoftGraphCalendar>]
[-CalendarGroups <IMicrosoftGraphCalendarGroup[]>]
[-CalendarView <IMicrosoftGraphEvent[]>]
[-Calendars <IMicrosoftGraphCalendar[]>]
[-Chats <IMicrosoftGraphChat[]>]
[-City <String>]
[-CompanyName <String>]
[-ConsentProvidedForMinor <String>]
[-ContactFolders <IMicrosoftGraphContactFolder[]>]
[-Contacts <IMicrosoftGraphContact[]>]
[-Country <String>]
[-CreatedDateTime <DateTime>]
[-CreatedObjects <IMicrosoftGraphDirectoryObject[]>]
[-CreationType <String>]
[-CustomSecurityAttributes <Hashtable>]
[-DeletedDateTime <DateTime>]
[-Department <String>]
[-DeviceEnrollmentLimit <Int32>]
[-DeviceManagementTroubleshootingEvents <IMicrosoftGraphDeviceManagementTroubleshootingEvent[]>]
[-DirectReports <IMicrosoftGraphDirectoryObject[]>]
[-DisplayName <String>]
[-Drive <IMicrosoftGraphDrive>]
[-Drives <IMicrosoftGraphDrive[]>]
[-EmployeeExperience <IMicrosoftGraphEmployeeExperienceUser>]
[-EmployeeHireDate <DateTime>]
[-EmployeeId <String>]
[-EmployeeLeaveDateTime <DateTime>]
[-EmployeeOrgData <IMicrosoftGraphEmployeeOrgData>]
[-EmployeeType <String>]
[-Events <IMicrosoftGraphEvent[]>]
[-Extensions <IMicrosoftGraphExtension[]>]
[-ExternalUserState <String>]
[-ExternalUserStateChangeDateTime <DateTime>]
[-FaxNumber <String>]
[-FollowedSites <IMicrosoftGraphSite[]>]
[-GivenName <String>]
[-HireDate <DateTime>]
[-Id <String>]
[-Identities <IMicrosoftGraphObjectIdentity[]>]
[-ImAddresses <String[]>]
[-InferenceClassification <IMicrosoftGraphInferenceClassification>]
[-Insights <IMicrosoftGraphOfficeGraphInsights>]
[-Interests <String[]>]
[-IsResourceAccount]
[-JobTitle <String>]
[-JoinedTeams <IMicrosoftGraphTeam[]>]
[-LastPasswordChangeDateTime <DateTime>]
[-LegalAgeGroupClassification <String>]
[-LicenseAssignmentStates <IMicrosoftGraphLicenseAssignmentState[]>]
[-LicenseDetails <IMicrosoftGraphLicenseDetails[]>]
[-Mail <String>]
[-MailFolders <IMicrosoftGraphMailFolder[]>]
[-MailNickname <String>]
[-MailboxSettings <IMicrosoftGraphMailboxSettings>]
[-ManagedAppRegistrations <IMicrosoftGraphManagedAppRegistration[]>]
[-ManagedDevices <IMicrosoftGraphManagedDevice[]>]
[-Manager <IMicrosoftGraphDirectoryObject>]
[-MemberOf <IMicrosoftGraphDirectoryObject[]>]
[-Messages <IMicrosoftGraphMessage[]>]
[-MobilePhone <String>]
[-MySite <String>]
[-Oauth2PermissionGrants <IMicrosoftGraphOAuth2PermissionGrant[]>]
[-OfficeLocation <String>]
[-OnPremisesDistinguishedName <String>]
[-OnPremisesDomainName <String>]
[-OnPremisesExtensionAttributes <IMicrosoftGraphOnPremisesExtensionAttributes>]
[-OnPremisesImmutableId <String>]
[-OnPremisesLastSyncDateTime <DateTime>]
[-OnPremisesProvisioningErrors <IMicrosoftGraphOnPremisesProvisioningError[]>]
[-OnPremisesSamAccountName <String>]
[-OnPremisesSecurityIdentifier <String>]
[-OnPremisesSyncEnabled]
[-OnPremisesUserPrincipalName <String>]
[-Onenote <IMicrosoftGraphOnenote>]
[-OnlineMeetings <IMicrosoftGraphOnlineMeeting[]>]
[-OtherMails <String[]>]
[-Outlook <IMicrosoftGraphOutlookUser>]
[-OwnedDevices <IMicrosoftGraphDirectoryObject[]>]
[-OwnedObjects <IMicrosoftGraphDirectoryObject[]>]
[-PasswordPolicies <String>]
[-PasswordProfile <IMicrosoftGraphPasswordProfile>]
[-PastProjects <String[]>]
[-People <IMicrosoftGraphPerson[]>]
[-Photo <IMicrosoftGraphProfilePhoto>]
[-Photos <IMicrosoftGraphProfilePhoto[]>]
[-Planner <IMicrosoftGraphPlannerUser>]
[-PostalCode <String>]
[-PreferredDataLocation <String>]
[-PreferredLanguage <String>]
[-PreferredName <String>]
[-Presence <IMicrosoftGraphPresence>]
[-Print <IMicrosoftGraphUserPrint>]
[-ProvisionedPlans <IMicrosoftGraphProvisionedPlan[]>]
[-ProxyAddresses <String[]>]
[-RegisteredDevices <IMicrosoftGraphDirectoryObject[]>]
[-Responsibilities <String[]>]
[-Schools <String[]>]
[-ScopedRoleMemberOf <IMicrosoftGraphScopedRoleMembership[]>]
[-SecurityIdentifier <String>]
[-ServiceProvisioningErrors <IMicrosoftGraphServiceProvisioningError[]>]
[-Settings <IMicrosoftGraphUserSettings>]
[-ShowInAddressList]
[-SignInActivity <IMicrosoftGraphSignInActivity>]
[-SignInSessionsValidFromDateTime <DateTime>]
[-Skills <String[]>]
[-State <String>]
[-StreetAddress <String>]
[-Surname <String>]
[-Teamwork <IMicrosoftGraphUserTeamwork>]
[-Todo <IMicrosoftGraphTodo>]
[-TransitiveMemberOf <IMicrosoftGraphDirectoryObject[]>]
[-UsageLocation <String>]
[-UserPrincipalName <String>]
[-UserType <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
In this article, we will discuss how to use the New-MgUser cmdlet in PowerShell to create a new user.
How to Create a New User in Microsoft Graph
To create a new user in Microsoft Graph, use the New-MgUser cmdlet in PowerShell.
# password for the new user $PasswordProfile = @{ Password = "xWwvJ]6NMw+bWH-d"} # Add the new user New-MgUser -DisplayName 'Luca Adkins' -PasswordProfile $PasswordProfile -AccountEnabled -MailNickname "LucaAdkins" -Mail "[email protected]" -UserPrincipalName "[email protected]"
The $PasswordProfile
variable stores the user password. The New-MgUser cmdlet in PowerShell creates a new user.
The output of the New-MgUser cmdlet includes the following properties.
- DisplayName: The display name of the user.
- Id: The unique identifier of the user.
- Mail: The SMPT address for the user.
- UserPrincipalName: The user principal name of the user.
New-MgUser FAQ
Connect to your Microsoft 365 tenant with the Connect-MgGraph cmdlet with the scope “User.ReadWrite.All“. To resolve the insufficient privileges issue, run the following command.
Connect-MgGraph -Scopes User.ReadWrite.All
Conclusion
I hope the above article on how to use the New-MgUser cmdlet in PowerShell to create a new user in Microsoft Graph is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.