Microsoft heeft recentelijk een nieuwe oplossing gelanceerd waarbij je via de Azure Portal, onder andere Office 365 licenties kan uitdelen aan groepen. Dit lijkt een mooie oplossing maar in onze test werkte het nog niet helemaal vlekkeloos.

Met onderstaand script kan je heel eenvoudig een licentie (voor bijvoorbeeld Office 365) uitdelen aan alle leden van een security groep. Het is daarbij wel vereist dat deze groep in de cloud is aangemaakt (of daar naartoe wordt gesynchroniseerd). We hebben geprobeerd om per regel uit te leggen wat er gebeurt en daarom zou dit redelijk makkelijk te lezen moeten zijn.

# Install the module (if not yet installed)
# Install-Module AzureAD # you need local admin to install modules....

# First connect to Azure AD
# You'll be asked for your admin credentials
$cred = Get-Credential
Connect-AzureAD -Credential $cred

# Set the username for the user that has the correct license
$username = "something@yourdomain.com"

# Find the license of that user
Get-AzureADUserLicenseDetail -ObjectId $username | Format-list

# Set the correct SkuId with one of these methods
[GUID]$sku = (Get-AzureADUserLicenseDetail -ObjectId $username).SkuId
# [GUID]$sku = '78e66a63-337a-4a9a-8959-41c6654dfb56'

# Create a licenses object
$license = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$license.SkuId = $sku
$licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$licenses.AddLicenses = $license

# An individual user can be given a license by using this line
Set-AzureADUserLicense -ObjectId "something@yourdomain.com" -AssignedLicenses $licenses
# You might have to set the correct location first
Set-AzureADUser -ObjectId "something@yourdomain.com" -UsageLocation NL
# Set wanted location
$location = NL
# Set the location by full groupname
$groupname = "yourgroup@yourdomain.com"
Get-AzureADGroup -ObjectId $groupname | Get-AzureADGroupMember -All $true | Where-Object -Property UsageLocation -Value $location -ne | Set-AzureADUser -UsageLocation $location
# Set the licenses by full groupname
Get-AzureADGroup -ObjectId $groupname | Get-AzureADGroupMember -All $true | Where-Object -Property AccountEnabled -Value $true -eq | Set-AzureADUserLicense -AssignedLicenses $licenses

# Set the licenses by part of the groupname (BE CAREFULL!!)
$searchQuery = "first_part_of_g"
Get-AzureADGroup -SearchString $searchQuery | Get-AzureADGroupMember -All $true | Where-Object -Property UsageLocation -Value $location -ne | Set-AzureADUser -UsageLocation $location
Get-AzureADGroup -SearchString $searchQuery | Get-AzureADGroupMember -All $true | Where-Object -Property AccountEnabled -Value $true -eq | Set-AzureADUserLicense -AssignedLicenses $licenses

Heb je nog een goede toevoeging voor dit script, laat dan hieronder een reactie achter. Ook als je weet hoe je het benodigde account op een veilige manier kan opslaan.

Mochten jullie als school interesse hebben om het lesrooster te synchroniseren met Office 365, kijk dan eens naar Roostersync.


0 reacties

Geef een antwoord

Het e-mailadres wordt niet gepubliceerd.