Control license allocation with the PowerShell in Microsoft 365!



Hi Microsoft 365 friends,


I used the PowerShell ISE for this configuration. But you are also very welcome to use Visual Studio Code, just as you wish. Please start with the following steps to begin the deployment (the Hashtags are comments):


#The first two lines have nothing to do with the configuration, but make some space below in the blue part of the ISE

Set-Location C:\Temp


#We need the PowerShell module
Install-Module MSOnline -AllowClobber -Force -Verbose

#Lets connect

#To find the unlicensed accounts in your organization
Get-MsolUser -All -UnlicensedUsersOnly

#To find accounts that don't have a UsageLocation value
Get-MsolUser -All | where {$_.UsageLocation -eq $null}

#View all users with Displayname and UsageLocation
Get-MsolUser -All | Format-Table DisplayName,Usagelocation -AutoSize

#List the licensing plans that are available in your organization

#List the services that are available in each licensing plan
(Get-MsolAccountSku | where {$_.AccountSkuId -eq "wechsler:ENTERPRISEPREMIUM"}).ServiceStatus

#This example shows the services to which the user has access
(Get-MsolUser -UserPrincipalName

#Set UsageLocation for a specific user
Set-MsolUser -UserPrincipalName "" -UsageLocation CH

#Add a license for a specific user
Set-MsolUserLicense -UserPrincipalName "" -AddLicenses "wechsler:ENTERPRISEPREMIUM"

#Set a license for all unlicensed users (maybe not the best option - be careful!!)
Get-MsolUser -All -UnlicensedUsersOnly | Set-MsolUserLicense -AddLicenses "wechsler:ENTERPRISEPREMIUM"

#We investigate a department
Get-MsolUser -All -Department "Administration" -UnlicensedUsersOnly | Select-Object DisplayName, UsageLocation, Islicensed

#Set UsageLocation for a specific user
Set-MsolUser -UserPrincipalName "" -UsageLocation CH

#A safer to add licenses to users
Get-MsolUser -All -Department "Administration" -UsageLocation "CH" -UnlicensedUsersOnly | Set-MsolUserLicense -AddLicenses "wechsler:ENTERPRISEPREMIUM"
Now you have used the PowerShell to investigate the license allocation in a Microsoft 365 environment! Congratulations!

I hope this article was useful. Best regards, Tom Wechsler


P.S. All scripts (#PowerShell, Azure CLI, #Terraform, #ARM) that I use can be found on github!

1 Reply