当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] New-MgUser - 在 Azure AD 中创建新用户

作者:精品下载站 日期:2024-12-14 06:28:11 浏览:12 分类:玩电脑

New-MgUser - 在 Azure AD 中创建新用户


用户管理是任何 Microsoft 365 环境中的一项基本任务,Microsoft Graph PowerShell 提供了通过 PowerShell 管理用户的 cmdlet。

PowerShell 中的 New-MgUser cmdlet 在 Microsoft Graph 中创建新用户。

要使用 New-MgUser cmdlet,必须首先使用 Connect-MGraph cmdlet 连接到 Microsoft 365 租户。连接后,您可以使用 New-MgUser cmdlet 创建新用户。

Connect-MgGraph -Scopes User.ReadWrite.All

下面给出了创建新用户对象的语法。

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>]

在本文中,我们将讨论如何在 PowerShell 中使用 New-MgUser cmdlet 创建新用户。

如何在 Microsoft Graph 中创建新用户

要在 Microsoft Graph 中创建新用户,请在 PowerShell 中使用 New-MgUser cmdlet。

# 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 " -UserPrincipalName "[email "

$PasswordProfile 变量存储用户密码。 PowerShell 中的 New-MgUser cmdlet 可创建新用户。

[玩转系统] New-MgUser - 在 Azure AD 中创建新用户

New-MgUser cmdlet 的输出包括以下属性。

  • DisplayName:用户的显示名称。
  • Id:用户的唯一标识符。
  • 邮件:用户的 SMPT 地址。
  • UserPrincipalName:用户的用户主体名称。

新Mg用户常见问题解答

New-MgUser 返回错误:New-MgUser:没有足够的权限来完成操作。

使用范围为“User.ReadWrite.All”的 Connect-MgGraph cmdlet 连接到 Microsoft 365 租户。要解决权限不足的问题,请运行以下命令。

Connect-MgGraph -范围 User.ReadWrite.All

结论

希望上述有关如何在 PowerShell 中使用 New-MgUser cmdlet 在 Microsoft Graph 中创建新用户的文章对您有所帮助。

您可以在 ShellGeek 主页上找到有关 PowerShell Active Directory 命令和 PowerShell 基础知识的更多主题。

相关链接

获取 MgUser

更新-MgUser

删除-MgUser

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯