Skip to content

Instantly share code, notes, and snippets.

@machv
Created June 26, 2019 16:28
Show Gist options
  • Save machv/bd03cb1fd14c60dd0e2b09f82daaa6bf to your computer and use it in GitHub Desktop.
Save machv/bd03cb1fd14c60dd0e2b09f82daaa6bf to your computer and use it in GitHub Desktop.
Enable Teams for 365 users
Connect-AzureAD
$skus = Get-AzureADSubscribedSku
$skus | Select -Property Sku*,ConsumedUnits -ExpandProperty PrepaidUnits | Select SkuPartNumber, ConsumedUnits, Enabled
$sku = $skus | where SkuPartNumber -eq "O365_BUSINESS_ESSENTIALS"
$sku.ServicePlans
$serviceToEnable = "57ff2da0-773e-42df-b2af-ffb7a2317929"
$users = Get-AzureADUser
$user = $users | Select -First 1 -Skip 2
foreach($user in $users) {
Set-AzureADUser -ObjectId $user.ObjectId -UsageLocation CZ
$license = $user.AssignedLicenses | where { $_.SkuId -eq $sku.SkuId }
if(!$license) {
continue
}
$disabled = $license.DisabledPlans | Sort
if(!$disabled)
{
$disabled = @() #full set of features
}
if(!$disabled.Contains($serviceToEnable)) {
continue
}
$License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$License.SkuId = $sku.SkuId
$License.DisabledPlans = ($disabled | where { $_ -ne $serviceToEnable})
$AssignedLicenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$AssignedLicenses.AddLicenses = $License
$AssignedLicenses.RemoveLicenses = @()
" - Updating license for {0}" -f $user.DisplayName
Set-AzureADUserLicense -ObjectId $user.ObjectId -AssignedLicenses $AssignedLicenses
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment