Created
April 30, 2020 05:47
-
-
Save technion/79a3286a576acfc7e49834a14ed4d31b to your computer and use it in GitHub Desktop.
Adds all AzureAD users with a certain license to a group
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
$skus = Get-AzureADSubscribedSku | |
# Exchange Online E1 | |
$skue1 = ( $skus | where { $_.skupartnumber -eq 'EXCHANGESTANDARD' } ).SkuID | |
$members = Get-AzureADUser -All $true | |
foreach($member in $members) { | |
if ($member.ImmutableId -eq $null) { | |
# Cloud user - skip | |
continue | |
} | |
$userlicenses = $member | Select -ExpandProperty AssignedLicenses | |
#Note and add to group if they have an additional E1 | |
if( $userlicenses | where { $_.Skuid -eq $skue1 } ) { | |
# Necessary because Get-ADGroupMember doesn't fetch the UserPrincipalName | |
$guid = ([GUID][System.Convert]::FromBase64String($member.ImmutableID)).Guid | |
$ADuser = Get-ADUser -Filter "objectGUID -eq '$guid' " | |
write-host "Adding user $($ADuser.UserPrincipalName) to group $($member.MailNickName)" | |
Add-ADGroupMember -Identity "LIC_E1" -Members $ADuser | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment