如何使用 New-MgUser 创建 Microsoft Entra ID 用户

创建 Microsoft Entra ID 用户

用户创建是 IT 管理员的一项关键任务,确保员工和外部协作者拥有安全访问权限,同时管理访问控制和安全策略。虽然 Graph PowerShell 的 New-MgUser 命令——作为 New-AzureADuser PowerShell 命令的替代方案——可用于创建 Microsoft Entra ID 用户,但该过程既耗时又容易出错,尤其是在处理大量账户或复杂的组织结构时。另一方面,ADManager Plus 作为一款 Microsoft 365 管理和报告工具,简化了这一任务,使管理员能够通过几次点击快速创建和管理 Microsoft Entra ID 用户。

  • ADManager Plus
  • PowerShell
 

使用 ADManager Plus 创建 Microsoft Entra ID 用户的步骤

  1. 登录 ADManager Plus 并导航至 管理 > 用户管理。
  2. 在用户创建下,点击 创建单个用户。
  3. 所选域 下拉列表中选择您希望创建用户的域。
  4. 选中 Microsoft 365 复选框。
  5. 填写必填信息并点击 Create
使用 ADManager Plus 创建 Microsoft Entra ID 用户
 
 

应用模板以一步自动配置多个用户属性。

 
 

从现有用户帐户复制值以填写模板字段。

使用 Microsoft Graph PowerShell 创建 Microsoft Entra ID 用户

前提条件

在使用 New-MgUser cmdlet 之前,请确保以下事项:

  • The Microsoft Graph PowerShell module is installed. If not, install it using this script:
    Install-Module Microsoft.Graph -Scope CurrentUser
  • Connect to Microsoft Graph PowerShell with the following permissions to create Microsoft Entra ID users.
    User.ReadWrite.All, Directory.ReadWrite.All,
    DeviceManagementServiceConfig.ReadWrite.All,
    DeviceManagementManagedDevices.ReadWrite.All,
    DeviceManagementConfiguration.ReadWrite.All,
    DeviceManagementApps.ReadWrite.All,

使用 New-MgUser 命令创建 Microsoft Entra ID 用户

New-MgUser cmdlet 可用于 Microsoft Graph PowerShell 中创建 Microsoft Entra ID 用户。语法如下:

New-MgUser
[-ResponseHeadersVariable <String>]
[-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>]
[-CloudClipboard <IMicrosoftGraphCloudClipboardRoot>]
[-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 <Hashtable>]
[-Interests <String[]>]
[-IsManagementRestricted]
[-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[]>]
[-PermissionGrants <IMicrosoftGraphResourceSpecificPermissionGrant[]>]
[-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[]>]
[-Solutions <IMicrosoftGraphUserSolutionRoot>]
[-Sponsors <IMicrosoftGraphDirectoryObject[]>]
[-State <String>]
[-StreetAddress <String>]
[-Surname <String>]
[-Teamwork <IMicrosoftGraphUserTeamwork>]
[-Todo <IMicrosoftGraphTodo>]
[-TransitiveMemberOf <IMicrosoftGraphDirectoryObject[]>]
[-UsageLocation <String>]
[-UserPrincipalName <String>]
[-UserType <String>]
[-Headers <IDictionary>]
[-ProgressAction <ActionPreference>]
[-WhatIf]
[-Confirm]<
[<CommonParameters>]

使用 New-MgUser cmdlet 的示例用例和脚本

创建新用户

$PasswordProfile = @{
Password = 'xWwvJ]6NMw+bWH-d'
}
New-MgUser -DisplayName 'Rene Magi' -PasswordProfile $PasswordProfile -AccountEnabled -MailNickName 'ReneMagi' -UserPrincipalName 'ReneMagi@contoso.com'

支持的参数

下表包含一些可与 New-MgUser 命令一起使用的参数,以高效创建 Microsoft Entra ID 用户。

参数 描述
-AccountEnabled 此参数决定用户帐户是否启用。
-Activities 此参数显示用户在各设备上的活动。
-AgeGroup 此参数设置用户的年龄组。
-AppRoleAssignments 此参数表示用户为某个应用程序授予的应用角色。
-AssignedLicenses 此参数决定要分配给用户的许可证。

使用 Graph PowerShell 脚本创建 Microsoft Entra ID 用户的限制

  • Graph PowerShell 要求 IT 管理员从 Azure AD PowerShell 升级并熟悉 PowerShell 脚本。
  • Microsoft Graph API 施加了限制流量的限制,可能会影响批量创建用户时的性能。
  • 识别和排查大规模用户创建脚本中的错误可能耗时且需要技术专长。
  • 脚本可能需要额外工作来格式化和导出数据以用于报告。
  • 无内置图形界面或用户友好报告,导致管理员管理和监控困难。

使用 ADManager Plus 创建 Microsoft Entra ID 用户的亮点

  • 通过用户友好的界面简化用户创建和 管理,无需 PowerShell 脚本或 Graph API 知识。
  • 通过 自动化 功能简化批量操作,优化大规模环境,消除复杂脚本的需求。
  • 使用预构建或 自定义模板 标准化管理和报告任务。
  • 生成 200 多个预设报告,支持 自定义 并导出为 CSV 或 HTML 等多种格式。
  • 委派 特定管理和报告任务给技术人员,而不授予过多权限。

使用 ADManager Plus 简化 Microsoft Entra ID 用户创建

 
  • 使用 ADManager Plus 创建 Microsoft Entra ID 用户
  • 使用 Microsoft Graph PowerShell 创建 Microsoft Entra ID 用户
  • 使用 Graph PowerShell 脚本创建 Microsoft Entra ID 用户的限制
  • 使用 ADManager Plus 创建 Microsoft Entra ID 用户的亮点
Active Directory管理与报告的一站式解决方案
电子邮件下载链接 Email the ADManager Plus download link