Add new guest user to azure powershell command
To add a new guest user to Azure using PowerShell, you can use the following command:
New-AzADUser -DisplayName "New Guest User" -UserPrincipalName "newguestuser@<tenant_name>.onmicrosoft.com" -MailNickname "newguestuser" -AccountEnabled $true -MailEnabled $true -UsageLocation "US" -Force
Replace <tenant_name>
with the name of your Azure Active Directory (AAD) tenant.
Here's a breakdown of the parameters:
-DisplayName
: The display name of the new user.-UserPrincipalName
: The UPN of the new user. This should be in the format<username>@<tenant_name>.onmicrosoft.com
.-MailNickname
: The nickname for the user's email address.-AccountEnabled
: A boolean value indicating whether the account is enabled or not. Set to$true
to enable the account.-MailEnabled
: A boolean value indicating whether the account is mail-enabled or not. Set to$true
to enable mail.-UsageLocation
: The location of the user. This is used for compliance and regulatory purposes.-Force
: A switch that forces the creation of the user without prompting for confirmation.
Once you run this command, the new guest user will be created in your Azure AD tenant. Note that guest users are not assigned to any Azure AD groups by default, so you may need to add them to a group manually using the Add-AzADGroupMember
cmdlet.
Here's an example of how to add the new guest user to a group:
Add-AzADGroupMember -GroupObjectId <group_object_id> -MemberObjectId (Get-AzADUser -UserPrincipalName "newguestuser@<tenant_name>.onmicrosoft.com").ObjectId
Replace <group_object_id>
with the object ID of the Azure AD group you want to add the user to.