Random split objects con Azure AD Dynamic Groups

Azure Active Directory ci permette di creare gruppi e di popolarli manualmente con risorse user e device a seconda delle nostre esigenze più disparate. Fino a qui niente di nuovo siccome da sempre con Active Directory on-premises siamo abituati a gestire gruppi e nesting.

Gli Azure Active Directory Dynamic Groups hanno una caratteristica utilissima rispetto i gruppi Active Directory. L’appartenenza la possiamo gestire staticamente (si vabbeh) oppure dinamicamente (wow che bello). Ci permettono di popolare dinamicamente i gruppi aggiungendo e rimuovendo automaticamente i membri del gruppo utilizzando regole di appartenenza basate sugli attributi dei membri. Per chi ha una esperienza con Configuration Manager (SCCM) possiamo tranquillamente paragonare lo scopo ed utilizzo dei Dynamic Groups alle Collections.

Sono oggetti a cui applicare Configuration profiles, Security baseline, Assegnazione Licenze, Script, Apps, Update rings, Conditional Access e tutto quello che riteniamo utile per un target specifico.

In cosa sono vincono a mani basse rispetto ad un gruppo statico? Vincono sul fatto che una volta impostato un attributo, un valore, un “richiamo”, non dobbiamo più preoccupare di dover inserire manualmente oggetti nei rispettivi gruppi per scatenare un’azione… ci penserà direttamente AAD a popolare il gruppo in base alla parametrizzazione che andremo ad impostare.

I Dynamic Groups richiedono una licenza di Azure AD Premium P1 per ogni utente membro di uno o più gruppi dinamici.
Non è necessaria alcuna licenza per i Dynamic Groups per device.

Non è necessario assegnare licenze agli utenti affinché siano membri di gruppi dinamici, ma è necessario disporre del numero minimo di licenze nell’organizzazione di Azure AD per coprire tutti questi utenti. La funzionalità è attiva sebbene la mancata copertura non soddisferebbe le condizioni di licenza di Microsoft.

Per creare ed utilizzare i Dynamic Groups vi rimando a questo utilissimo URL in cui vengono spiegati passo passo tutti i passaggi: Create or edit a dynamic group and get status – Microsoft Entra | Microsoft Learn

Figure 1 – Azure AD Dynamic Groups

Ultimamente ho avuto l’esigenza di creare gruppi dinamici popolati in modalità completamente casuale che mi aiutassero a collocare omogeneamente tutte le risorse. Mi è capitato spesso in realtà enterprise di trovarmi in difficoltà nel “diluire” la distribuzione di un software o di un upgrade build a diverse centinaia o anche migliaia di device. Collocarli in gruppi random dinamici e suddividerli in gruppi da 4, 8 oppure 16 può esser d’aiuto e qui vi illustro come fare.

L’idea è quella di utilizzare il deviceID delle macchine che è stringa esadecimale composta da caratteri distinti che iniziano con un valore da 0 – 9 oppure da A – F (16 in totale).

Per comodità di calcolo facciamo finta che l’azienda in questione abbia 1600 device Windows. Sfruttando i Dynamic Groups potrò ottenere:
4 gruppi dinamici popolati in modo casuale di 400 Windows devices
8 gruppi dinamici popolati in modo casuale di 200 Windows devices
16 gruppi dinamici popolati in modo casuale di 100 Windows devices

Figure 2 – Azure AD Dynamic Groups split a quattro gruppi e Rule Syntax

Suddivisione a 4 gruppi dinamici popolati in modo casuale di 400 Windows devices e Rule Syntax

MEM Device – Windows group All
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”)

MEM Device – Windows group 25% 1/4
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and ((device.deviceId -startsWith “0”) or (device.deviceId -startsWith “1”) or (device.deviceId -startsWith “2”) or (device.deviceId -startsWith “A”))

MEM Device – Windows group 25% 2/4
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and ((device.deviceId -startsWith “3”) or (device.deviceId -startsWith “4”) or (device.deviceId -startsWith “5”) or (device.deviceId -startsWith “B”))

MEM Device – Windows group 25% 3/4
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and ((device.deviceId -startsWith “6”) or (device.deviceId -startsWith “7”) or (device.deviceId -startsWith “8”) or (device.deviceId -startsWith “C”))

MEM Device – Windows group 25% 4/4
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and ((device.deviceId -startsWith “9”) or (device.deviceId -startsWith “D”) or (device.deviceId -startsWith “E”) or (device.deviceId -startsWith “F”))

 

Suddivisione 8 gruppi dinamici popolati in modo casuale di 200 Windows devices e Rule Syntax

MEM Device – Windows group 12.5% 1/8
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and ((device.deviceId -startsWith “0”) or (device.deviceId -startsWith “A”))

MEM Device – Windows group 12.5% 2/8
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and ((device.deviceId -startsWith “1”) or (device.deviceId -startsWith “B”))

MEM Device – Windows group 12.5% 3/8
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and ((device.deviceId -startsWith “2”) or (device.deviceId -startsWith “C”))

MEM Device – Windows group 12.5% 4/8
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and ((device.deviceId -startsWith “3”) or (device.deviceId -startsWith “D”))

MEM Device – Windows group 12.5% 5/8
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and ((device.deviceId -startsWith “4”) or (device.deviceId -startsWith “E”))

MEM Device – Windows group 12.5% 6/8
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and ((device.deviceId -startsWith “5”) or (device.deviceId -startsWith “F”))

MEM Device – Windows group 12.5% 7/8
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and ((device.deviceId -startsWith “6”) or (device.deviceId -startsWith “7”))

MEM Device – Windows group 12.5% 8/8
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and ((device.deviceId -startsWith “8”) or (device.deviceId -startsWith “9”))

Figure 3 – Risultato Azure AD Dynamic Groups split a quattro e otto gruppi

Suddivisione a 16 gruppi dinamici popolati in modo casuale di 100 Windows devices e Rule Syntax

MEM Device – Windows group 6.25% 1/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “0”)

MEM Device – Windows group 6.25% 2/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “1”)

MEM Device – Windows group 6.25% 3/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “2”)

MEM Device – Windows group 6.25% 4/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “3”)

MEM Device – Windows group 6.25% 5/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “4”)

MEM Device – Windows group 6.25% 6/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “5”)

MEM Device – Windows group 6.25% 7/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “6”)

MEM Device – Windows group 6.25% 8/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “7”)

MEM Device – Windows group 6.25% 9/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “8”)

MEM Device – Windows group 6.25% 10/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “9”)

MEM Device – Windows group 6.25% 11/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “A”)

MEM Device – Windows group 6.25% 12/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “B”)

MEM Device – Windows group 6.25% 13/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “C”)

MEM Device – Windows group 6.25% 14/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “D”)

MEM Device – Windows group 6.25% 15/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “E”)

MEM Device – Windows group 6.25% 16/16
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “MDM”) and (device.deviceId -startsWith “F”)

 

Ricordate che ad inizio articolo ho paragonato gli Active Directory Dynamic Groups alle SCCM Collections?

Attraverso la stessa logica possiamo suddividere dinamicamente tutti i devices in più collections
Al posto di utilizzare il deviceID di Azure andremo a richiamare il ResourceID che è una stringa creata automaticamente da SCCM che termina con 0-9. In questo modo avremo la possibilità di ottenere 10 Collections che si divideranno approssimativamente il 10% del totale.

A seguire la sintassi WQL per popolare la collection:

select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ResourceId like “%1” and SMS_R_System.OperatingSystemNameandVersion like “%Workstation%”

select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ResourceId like “%2” and SMS_R_System.OperatingSystemNameandVersion like “%Workstation%”

La figura qui sotto riporta il risultato finale:

Figure 4 – SCCM Split Collections

Se lo split in decimi contiene troppi devices possiamo anche qui appoggiarci ad una stringa esadecimale basata sul Configuration Manager Unique Identifier (GUID).

Con questo metodo avremo le 16 Collections con percentuali del 6.25%

A seguire la sintassi WQL per popolare la collection:
SELECT * FROM SMS_R_System where SMS_R_System.SMSUniqueIdentifier LIKE “%0”

Proseguire poi con LIKE “%1” e tutti i caratteri fino all’ottenimento delle 16 collections.

 

Ne approfitto lasciandovi una serie di Rule Syntax che ho raccolto nel corso degli anni ed ho trovato molto utili per popolare gli Azure AD Dynamic Groups.
N.b.: li trovate tutti con il prefisso MEM siccome sapete bene quanto MS si diverta a cambiar nome ai prodotti

Dynamic Groups relativi ad Azure AD Join

MEM Device Windows Azure AD Join
(device.deviceTrustType -eq “AzureAD”)

MEM Device Windows Azure AD Hybrid Join
(device.deviceTrustType -eq “ServerAd”)

MEM Device Windows Azure AD registerd
(device.profileType -eq “RegisteredDevice”)

 

Dynamic Groups relativi agli utenti

MEM Group Tier Users
(user.userPrincipalName -contains “.365@”) or (user.userPrincipalName -contains “.Azure@”)

MEM Group Departements
(user.department -eq “Sales”) -and -not (user.jobTitle -contains “Ita”)

MEM Group DirSyncEnabled
(user.accountEnabled -eq True) and (user.dirSyncEnabled -eq True) and (user.userType -ne “Guest”)

MEM User Intune Service Enabled (identificato dal nome del servizio “SCO”)
user.assignedPlans -any (assignedPlan.service -eq “SCO” -and assignedPlan.capabilityStatus -eq “Enabled”)

MEM User MFA Service Enabled
user.assignedPlans -any (assignedPlan.service -eq “MultifactorService” -and assignedPlan.capabilityStatus -eq “Enabled”)

MEM User AAD plan Service Enabled
user.assignedPlans -any (assignedPlan.service -eq “AADPremiumService” -and assignedPlan.capabilityStatus -eq “Enabled”)

MEM User senza piano di servizio assegnato
user.assignedPlans -all (assignedPlan.servicePlanId -eq “”)

MEM All User & Guest
user.objectId -ne null

MEM All User
(user.objectId -ne null) and (user.userType -eq “Member”)

 

Dynamic Groups relativi ad Intune

MEM Device Autopilot Ready
(device.devicePhysicalIDs -any _ -contains “[ZTDId]”)

MEM Device Windows Hybrid Join without Inutune enrollment
(device.deviceOSType -eq “Windows”) and (device.managementType -eq “None”)

MEM Device – Autopilot TAG
(device.devicePhysicalIds -any _ -eq “[OrderID]:AADHJ”)

 

Dynamic Groups relativi al Sistema Operativo

MEM Devices All
device.objectId -ne null

MEM Device Windows 10
(device.deviceOSVersion -startsWith “10.0.1”)

MEM Device Windows 11
(device.deviceOSVersion -startsWith “10.0.2”)

MEM Device Windows 10 and 11
(device.deviceOSVersion -contains “10.0”)

MEM Device – All Windows 10 1709 <=
(device.deviceOSVersion -contains “10.0.16299”) or (device.deviceOSVersion -contains “10.0.15063”) or (device.deviceOSVersion -contains “10.0.14393”) or (device.deviceOSVersion -contains “10.0.10586”) or (device.deviceOSVersion -contains “10.0.10240”)

MEM Device Windows 10 1909
(device.deviceOSVersion -startsWith “10.0.18363”)

MEM Device Windows 10 2004
(device.deviceOSVersion -startsWith “10.0.19041”)

MEM Device Windows 10 21H1
(device.deviceOSVersion -startsWith “10.0.19043”)

MEM Device Android
(device.deviceOSType -contains “Android”)

MEM Device iPhone
(device.deviceOSType -contains “iPhone”)

 

Dynamic Groups relativi all’Hardware

MEM Device – All Surface
(device.deviceModel -contains “Surface”)

MEM Device – Latitude 7400
(device.deviceModel -contains “Latitude 7400”)

MEM Device – All Laptops
(device.deviceModel -contains “elite”) or (device.deviceModel -contains “notebook”) or (device.deviceModel -contains “elitebook”) or (device.deviceModel -contains “latitude”) or (device.deviceManufacturer -contains “LENOVO”) or (device.deviceManufacturer -contains “ACER”)

 

Come avete appena visto i benefici portati nell’utilizzo dei Dynamic Groups sono molteplici e la loro flessibilità ci permette di creare quegli automatismi che possono rendere l’attività di chi gestisce Azure AD, Intune ed i prodotti M365 molto più snella.