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:

Connect-MsolService

Creaating user:

New-MsolUser -UserPrincipalName lcage@<domainname>.onmicrosoft.com -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 https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

#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
Advertisements

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

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

Twitter picture

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

Facebook photo

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

w

Connecting to %s