Skip to content

Instantly share code, notes, and snippets.

@sob
Created August 19, 2020 23:46
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 sob/fe44d2e7d128ef99171eebe7dfe59198 to your computer and use it in GitHub Desktop.
Save sob/fe44d2e7d128ef99171eebe7dfe59198 to your computer and use it in GitHub Desktop.
$freshmen = Get-AzureADUser -All $true | Where-Object {$_.Mail -like '*2024@my.corpuschristisaints.org'}
$freshmen | ForEach-Object {
Write-Host "Removing User " $_.UserPrincipalName "..."
Write-Host -NoNewline -ForegroundColor DarkGreen "- Removing Licenses "
$licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$licenses.AddLicenses = @()
$licenses.RemoveLicenses = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value "M365EDU_A3_STUUSEBNFT" -EQ).SkuID
Set-AzureADUserLicense -ObjectId $_.UserPrincipalName -AssignedLicenses $licenses
Write-Host -ForegroundColor Green " done!"
Write-Host -NoNewLine -ForegroundColor DarkGreen "- Removing User"
Write-Host -ForegroundColor Green " done!"
Write-Host
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment