In this post, we will create a new user on Microsoft Azure using the PowerShell Az module.
The Microsoft Azure Az PowerShell is the most advanced module out of all the official Azure PowerShell modules and also allows us to manage Azure users and groups.
To get started and connect, I will use the following cmd, which will not open a prompt window for auth but will preset and one-time code and a link to authentication (If you are on WSL, use this option)
After connecting to Azure, we need first to set the user password using a secure string variable.
$Password = ConvertTo-SecureString -String "TYPE_PASSWORD" -AsPlainText -Force
Once the password is set, add the user details (DisplayName and Email) and run the cmdlet.
New-AzADUser -DisplayName "USER" -UserPrincipalName "USER_EMAIL" -Password $Password
To add the user to a security group, use the cmdlet below with the Group details and user details.
Add-AzADGroupMember -MemberUserPrincipalName USEREMAIL -TargetGroupDisplayName "GROUP_NAME"
To check group membership, use the code below.
Get-AzADGroupMember -GroupDisplayName "GROUP_NAME"
Leave a Reply