Creating user in Azure AD using PowerShell

Posted: October 29, 2017 in Azure

In this post we created Azure AD user using Azure portal, in this one we’ll do the same using PowerShell

Install Azure AD module

Install-Module MSOnline -Force | Import-Module

Connect to Azure:


Creaating user:

New-MsolUser -UserPrincipalName lcage@<domainname> -DisplayName 'Luke Cage' -FirstName 'Luke' -LastName 'Cage' -Password 'Pa55w.rd' -ForceChangePassword $false -UsageLocation 'RS'

User location is a valid ISO 3166-1 alpha-2 country code

#Create group
New-MsolGroup -DisplayName 'GroupName' -Description 'Azure group'

$group = Get-MsolGroup | Where-Object DisplayName -eq 'GroupName'

$user = Get-MsolUser | Where-Object DisplayName -eq 'Luke Cage'
#Add user to group
Add-MsolGroupMember -GroupObjectId $group.ObjectId -GroupMemberType 'User' -GroupMemberObjectId $user.ObjectId

Get-MsolGroupMember -GroupObjectId $group.ObjectId

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s