Control license allocation with the PowerShell in Microsoft 365!

MVP

 

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
Clear-Host

 

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

#Lets connect
Connect-MsolService

#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
Get-MsolAccountSku

#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 jane.ford@tomwechsler.xyz has access
(Get-MsolUser -UserPrincipalName jane.ford@tomwechsler.xyz).Licenses.ServiceStatus

#Set UsageLocation for a specific user
Set-MsolUser -UserPrincipalName "info@wechsler.onmicrosoft.com" -UsageLocation CH

#Add a license for a specific user
Set-MsolUserLicense -UserPrincipalName "info@wechsler.onmicrosoft.com" -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 "jane.dodge@tomwechsler.xyz" -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! https://github.com/tomwechsler

0 Replies