Creating Test Users for CRM Online with PowerShell

After a while you get tired of creating a few test users and look for an automated approach. Here's a simple PowerShell that you can drop into a CreateUser.ps1 file and run to create some users. It doesn't assign CRM roles, but it does take care of the Office 365 part including assigning the CRM license. If you want you could enhance this to pull the list of users from a file using the Import-Csv cmdlet

Prior to runing the script you will need to have already setup the PowerShell Cmdlets from here

  [string]$tenantName = $(Read-Host "Input Tenant Name")


$crmlicense = $tenantName+":CRMSTANDARD"

function CreateUser([string] $displayName,[string] $firstName,
[string] $lastName,[string] $upn,
[string] $license,[string] $tenantName)

    $fullupn = "{0}@{1}" -f $upn, $tenantName

   New-MsolUser -DisplayName $displayName -FirstName $firstName 
   -LastName $lastName -UserPrincipalName $fullupn  
   –Department Operations -UsageLocation US
   -LicenseAssignment $license -ForceChangePassword $FALSE 
   -Password pass@word1

CreateUser "GM" "General" "Manager" "gm" $crmlicense $tenantName
CreateUser "VPM" "VP" "Marketing" "vpm" $crmlicense $tenantName
CreateUser "VPS" "VP" "Sales" "vps" $crmlicense $tenantName

You can find the complete reference for New-MsolUser here