Skip to content

Instantly share code, notes, and snippets.

@aaronparker
Created December 1, 2018 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronparker/8085def46bcb3312210d423b049ffda0 to your computer and use it in GitHub Desktop.
Save aaronparker/8085def46bcb3312210d423b049ffda0 to your computer and use it in GitHub Desktop.
Find users registered in Intune with EMS E3 and replace with EMS E5 licenses
# Connect to Office 365
Connect-MsolService
# Get specific user accounts
Get-MsolUser -UserPrincipalName "bill.murray@stealthpuppy.com"
# Get license SKUs
Get-MsolAccountSku
# EMS licenses
$emsE3 = "stealthpuppy:EMS"
$emsE5 = "stealthpuppy:EMSPREMIUM"
$availableEmsE5 = Get-MsolAccountSku | Where-Object { $_.AccountSkuId -eq $($emsE5) }
# Get users with assigned EMS licenses
Get-MsolUser | Where-Object { $_.Licenses.AccountSkuId -eq $emsE3 } | Sort-Object -Property userPrincipalName
Get-MsolUser | Where-Object { $_.Licenses.AccountSkuId -eq $emsE5 } | Sort-Object -Property userPrincipalName
$emsE3Users = Get-MsolUser | Where-Object { $_.Licenses.AccountSkuId -eq $emsE3 } | Sort-Object -Property userPrincipalName | Select-Object userPrincipalName
# Connect to Intune
Import-Module ./Microsoft.Graph.Intune.psd1
Connect-MSGraph
# Get Intune managed devices
$intuneUsers = Get-IntuneManagedDevice | Select-Object -Property userPrincipalName -Unique
ForEach ($user in $intuneUsers) {
Write-Host -ForegroundColor Green "Getting details for user $($user.userPrincipalName)."
$msolUser = Get-MsolUser -UserPrincipalName $($user.userPrincipalName)
If ($msolUser.Licenses.AccountSkuId -eq $emsE3) {
Write-Host -ForegroundColor Green "Replacing license for $($user.userPrincipalName)"
Set-MsolUserLicense -UserPrincipalName $user.userPrincipalName -RemoveLicenses $emsE3 -AddLicenses $emsE5 -Verbose
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment