Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Creating a new user in Azure AD using oneliner PowerShell and Azure CLI

I was testing few Labs on Microsoft Azure active directory and wanted to create few Azure AD users for testing purpose. I have already installed az powershell module, In the below script when you supply password it has to be in securestring format. 

How to switch to other Azure AD tenant using PowerShell and Azure CLI
Powershell Azure Az module Install-Package cannot convert value 2.0.0-preview to type system.version 

#Secret Password
$secureStrPassword = ConvertTo-SecureString -String 'T0p$ecret!' -AsPlainText -Force

#Create User
New-AzADUser -DisplayName DemoUser -UserPrincipalName DemoUser@vcloudlabcomonmicrosoft.com -Password $secureStrPassword -MailNickname DemoUser -ForceChangePasswordNextLogin

Microsoft Azure AD active directory powershell create users secure str password convertto-securestring asplaintext new-azaduser userprincipalname azurecli automation utomation azure active directory powershell az module.png

If you want to create a user on the Azure Active Directory portal, you can follow below steps on the users | All Users click New user. Provide identity information and click create.

Microsoft Azure Active Directory azuread New user creation all users guest user bulk operation invite user Powershell azure cli portal onmicrosoft.com.png

Below script creates bulk users, I am creating 5 users naming starting from User1 to User5 in serial. I am using foreach-object loop to create users.

#Secret Password
$secureStrPassword = ConvertTo-SecureString -String 'T0p$ecret!' -AsPlainText -Force

#Create User
1..5 | % {New-AzADUser -DisplayName "User$_" -UserPrincipalName "User$_@vcloudlabcomonmicrosoft.com" -Password $secureStrPassword -MailNickname "User$_" -ForceChangePasswordNextLogin} | Select-Object DisplayName, UserPrincipalName

Microsoft Azure Active Directory azure ad powershell convertto-securestring new-azaduser userprincipalname forcechangepasswordnextlogin displayname select-object automation onmicrosoft.com.png

This is the screenshot after creating bulk users in Azure Active Directory from PowerShell one-liner script.

Microsoft Azure Active Directory AzureAD azurecloude powershell all users users domain name onmicrosoft.com multi-factor authentication mfa password reset.png

This example is from Azure CLI command to create Azure AD user.

#Azure CLI command example to create Azure AD user
az ad user create --display-name 'Test User' --password 'T0p$ecret' --user-principal-name testuser@vcloudlabcom.onmicrosoft.com --force-change-password-next-login true

Microsoft azure active directory azure cli powershell az ad user create --displayname --password --user-principal --force-change-password-next-login powershell automation.png

Useful Articles
CREATE NEW NSG (NETWORK SECURITY GROUP - VIRTUAL FIREWALL ACL) ON MICROSOFT AZURE  
POWERSHELL - EXPORT AZURE NSG (NETWORK SECURITY GROUP) RULES TO EXCEL
MICROSOFT AZURE POWERSHELL: CREATING NEW NSG (NETWORK SECURITY GROUP)
MICROSOFT AZURE POWERSHELL: CLONING (COPING) OR IMPORTING EXISTING NSG (NETWORK SECURITY GROUP) FROM EXCEL
Part 1: Create and deploy a website with Microsoft Azure web app service plan
Part 2: Configure a custom domain in Azure Web Apps
Part 3: Uploading to Azure Web Apps Using FTP
Part 4: Add and manage TLS SSL certificates on Azure Web App

Go Back



Comment

Blog Search

Page Views

11239908

Follow me on Blogarama