Created
December 1, 2018 12:32
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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