Somebody know if it is possible to how to create Dynamic membership rules for groups in Azure Active Directory from powershell instead of passing from “Rule builder in the Azure portal” ?
Thank you
CodePudding user response:
I tried to reproduce the same in my environment to create dynamic membership rules for groups in Azure Active Directory from powershell
As I tried below script to create dynamic membership rules for groups in Azure Active Directory from powershell
You can get the Administrative units Object ID like below
AzurePortal>Administrative units>Select your Administrative Unit>Properties (Preview)
You can get the Group Object ID like below
AzurePortal>Azure Active Directory>Groups>Select your Group>
#Install Azure AD Module
Install-Module -Name AzureADPreview
#Connect to Azure Account
Connect-AzureAD
#Get AzureADMSAdministrativeUnit Details
Get-AzureADMSAdministrativeUnit -id <AzureADMSAdministrativeUniObjectID>
#Create Dynamic membership rules to Exiting AzureADMSAdministrativeUnit
Set-AzureADMSAdministrativeUnit -Id <AzureADMSAdministrativeUnit ObjectID> -MembershipRule '(user.Department -eq "HR") -or (user.usageLocation -eq "India")'
#Get Azure AD Group details
Get-AzureADMSGroup -id <AzureADMSGroupobjectID>
#Create Dynamic membership rules to AzureAD group
Set-AzureADMSGroup -id <AzureADMSGroupobjectID> -MembershipRule '(user.Department -eq "IT") -or (user.usageLocation -eq "Canada")'
#Create New group with Dynamic Membership rule
New-AzureADMSGroup -DisplayName "Dynamic Group 01" -Description "Dynamic group created from PS" -MailEnabled $False -MailNickName "group" -SecurityEnabled $True -GroupTypes "DynamicMembership" -MembershipRule "(user.department -contains ""Marketing"")" -MembershipRuleProcessingState "On"
Finally Created Group with Dynamic Membership Rule
CodePudding user response:
Thank you for your detailled answer with the captures. I tried but it does'not work.
- I installed modules in Powershell:
Install-Module -Name AzureAD Install-Module -Name AzureADPreview Import-Module AzureAD Import-Module AzureADPreview Get-Module -Name AzureADPreview ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Binary 2.0.2.129 AzureADPreview {Add-
- Created Group
New-AzureADMSGroup -DisplayName "GR-TEST-01" -MailEnabled $false -SecurityEnabled $true -MailNickName "group"
- Created Dynamic Rule
Set-AzureADMSGroup -id 50114fb2-3c4d-4e65-95d4-5f8a7fa01d1e -MembershipRule '(user.userType -eq "Member") and (user.mailNickname -contains ".")'
But when i check on AZure Portal there is not the Dynamic Rule created Membership type is on "Assigned" not on "Dynamic Device"