首页 > 解决方案 > 如何创建动态 Office 365 组

问题描述

我是 Exchange Online 和 Azure 的新手,但有人问我是否可以使用 New-UnifiedGroup 和 Set-UnifiedGroup cmdlet 在 Exchange Online 中创建 O365 组。然后他们希望能够根据某些标准使这些群体充满活力。这是否可能,或者我是否完全跳过 Exchange Online,并在 Azure 中使用 New-AzureADMSGroup cmdlet 创建一个动态组。

任何帮助表示赞赏。谢谢。

标签: azurepowershellexchange-server

解决方案


好的,这就是我们提出的解决方案。

需要 AzureADPreview 模块,截至今天的当前版本 2.0.2.17

AzureAD 模块无法工作,因为它缺少组成员身份所需的参数。

需要连接到 AzureAD 以及 Exchange Online。

您连接的帐户需要是 Exchange Online 中的 Exchange 管理员和 AzureAD 中的用户管理员。在我们的示例中,我们需要一个动态的 Office 组,以及基于 extensionattribute12 的 membersRule。

#***********************************************************************
$ADUser = "samAccountName@yourdomain"
$ADPassword = 'the password'
$ADPwd = $ADPassword | ConvertTo-SecureString -AsPlainText -Force
$UserCredential = new-object system.management.automation.pscredential $ADuser, $ADPwd
#***********************************************************************
"Connect AzureAD"
Connect-AzureAD -Credential $UserCredential

"Connect to Exchange Online"
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking

#######################################
function ConvertStaticGroupToDynamic
{
     Param([string]$groupId, [string]$dynamicMembershipRule)
     $dynamicGroupTypeString = "DynamicMembership"
     #existing group types
     [System.Collections.ArrayList]$groupTypes = (Get-AzureAdMsGroup -Id $groupId).GroupTypes

     if($groupTypes -ne $null -and $groupTypes.Contains($dynamicGroupTypeString))
     {
         throw "This group is already a dynamic group. Aborting conversion.";
     }
     #add the dynamic group type to existing types
     $groupTypes.Add($dynamicGroupTypeString)

     #modify the group properties to make it a static group: i) change GroupTypes to add the dynamic type, ii) start execution of the rule, iii) set the rule
     Set-AzureAdMsGroup -Id $groupId -GroupTypes $groupTypes.ToArray() -MembershipRuleProcessingState "On" -MembershipRule $dynamicMembershipRule
}
#######################################
$ExtAtt12 = "Marketing"
$NewGroupName = "O365-OfficeGroupTest"
"[$NewGroupName] create group"
New-UnifiedGroup -DisplayName $NewGroupName
Set-UnifiedGroup $NewGroupName -UnifiedGroupWelcomeMessageEnabled:$false
$ID = (Get-UnifiedGroup $NewGroupName).ExternalDirectoryObjectId
sleep 15 # Allow time for Exchange Online to Sync with AzureAD
ConvertStaticGroupToDynamic -groupId $ID -dynamicMembershipRule "(User.extensionattribute12 -eq ""$ExtAtt12"")"

推荐阅读