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
$PasswordProfile.Password="YOUR_DEFAULT_PASSWORD"

Import-Csv .\users.csv | foreach-object {
	$usernameSplit = $_.UserName.Split("@")
	$usernameSplit[0]
	$usernameSplit[1]
	$userDisplayNameSplit = $usernameSplit[0].Split(".")
	$userDisplayNameSplit[0]
	$userDisplayNameSplit[1]
	$mailNickName = ($usernameSplit[0])
	$userprinicpalname = $usernameSplit[0] + "@YOUR_DEV_TENANT_NAME.onmicrosoft.com"
	$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 
FIRSTNAME.LASTNAME@company.com

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

Happy coding !

Comments (1) -

EWAhMUbK1Jq 9/26/2019 3:19:02 PM

374397 10533Wow! This can be one particular of the most useful blogs We have ever arrive across on this subject. Actually Great. I�m also an expert in this topic so I can understand your hard work. 559320

Add comment