Create users for Office 365 Dev Program

I am sharing a small PowerShell script to create at glance Office 365 users in Azure AD and assign them the E3 developer license.

$license = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses

$license.SkuId = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value "DEVELOPERPACK" -EQ).SkuID

$licenses.AddLicenses = $license

$PasswordProfile=New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile

Import-Csv .\users.csv | foreach-object {
	$usernameSplit = $_.UserName.Split("@")
	$userDisplayNameSplit = $usernameSplit[0].Split(".")
	$mailNickName = ($usernameSplit[0])
	$userprinicpalname = $usernameSplit[0] + ""
	$displayNanme = ($usernameSplit[0] + " " + $usernameSplit[1])
	New-AzureADUser -DisplayName $displayNanme -GivenName $userDisplayNameSplit[0] -SurName $userDisplayNameSplit[1] -UserPrincipalName $userprinicpalname -PasswordProfile $PasswordProfile -mailNickName $mailNickName -UsageLocation CH -AccountEnable $true
	# Call the Set-AzureADUserLicense cmdlet to set the license.
	Set-AzureADUserLicense -ObjectId $userprinicpalname -AssignedLicenses $licenses

The cvs file is just one column name UserName containing email in the form of

If you have emails in other format you can just modify the lines before the New-AzureADUser command.

Happy coding !