PowerShell – Create users in Dynamics 365

To Create a user in Office 365 which will then percolate to as a user in Dynamics 365 we need to do the following:

  1. Login to Dynamics (Office 365)
  2. Create a user in office 365
  3. Assign Dynamics License to that user
  4. Wait for a few minutes and check in dynamics the user should be created as enabled.


Setup your local machine for executing Azure and Office PowerShell Scripts. For more details refer this link: https://docs.microsoft.com/en-us/office365/enterprise/powershell/connect-to-office-365-powershell .

Open PowerShell in admin mode, then do the following steps:

Step 1)

Install-Module -Name AzureAD

Step 2)

Install-Module MSOnline

Step 3)

Import-Module MSOnline

Note: At this step you might get an exception to install only digitally signed assemblies, to overcome this we can execute the following command.

Step 3.1)

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Step 4)


Step 5) Following function encapsulates user creation with parameters

In the following code “DYN365_ENTERPRISE_PLAN1” is the license plan name for the organization when I created , it might be different for you based on your subscriptions.

$tenantName = "sayantanadobe"
$crmlicense = $tenantName+":DYN365_ENTERPRISE_PLAN1"
function CreateUser([string] $displayName,[string] $firstName,[string] $lastName,[string] $upn,[string] $license,[string] $tenantName)
$fullupn = "{0}@{1}.onmicrosoft.com" -f $upn, $tenantName
New-MsolUser -DisplayName $displayName -FirstName $firstName -LastName $lastName -UserPrincipalName $fullupn  –Department Operations -UsageLocation US -LicenseAssignment $license -ForceChangePassword $FALSE -Password pass@word1

Step 6) Now call the above function with the following statement to create a new user

CreateUser "Test User" "Test" "User" "test1" $crmlicense $tenantName
  • Thank You

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 )

Twitter picture

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

Facebook photo

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

Connecting to %s