diff --git a/CHANGELOG.md b/CHANGELOG.md index b280da23f7..c436c282bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ * Added support for AccessTokens. * IntuneAndroidManagedStoreAppConfiguration * Initial release. +* TeamsUserPolicyAssignment + * Added support for the Global policies. +* TeamsUpgradePolicy + * DEPRECATED: Users properties. Use the TeamsUserPolicyAssignment resource + instead. * MISC * Removed hardcoded Graph urls and replaced by MSCloudLoginAssistant values. diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_TeamsUpgradePolicy/MSFT_TeamsUpgradePolicy.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_TeamsUpgradePolicy/MSFT_TeamsUpgradePolicy.psm1 index e845b47cb9..7bbc0ac35a 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_TeamsUpgradePolicy/MSFT_TeamsUpgradePolicy.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_TeamsUpgradePolicy/MSFT_TeamsUpgradePolicy.psm1 @@ -8,6 +8,7 @@ function Get-TargetResource [System.String] $Identity, + # DEPRECATED [Parameter()] [System.String[]] $Users, @@ -66,22 +67,6 @@ function Get-TargetResource $policy = Get-CsTeamsUpgradePolicy -Identity $Identity ` -ErrorAction SilentlyContinue - if ($Identity -eq 'Global') - { - [array]$users = Get-CsOnlineUser -Filter "TeamsUpgradePolicy eq null" - } - else - { - try - { - [array]$users = Get-CsOnlineUser -Filter "TeamsUpgradePolicy eq '$Identity'" - } - catch - { - [array]$users = Get-CsOnlineUser | Where-Object -Filter { $_.TeamsUpgradePolicy -eq $Identity } - } - } - if ($null -eq $policy) { throw "No Teams Upgrade Policy with Identity {$Identity} was found" @@ -95,7 +80,8 @@ function Get-TargetResource Write-Verbose -Message "Found Teams Upgrade Policy with Identity {$Identity}" return @{ Identity = $Identity - Users = $usersList + #DEPRECATED + #Users = $usersList MigrateMeetingsToTeams = $MigrateMeetingsToTeams Credential = $Credential ApplicationId = $ApplicationId @@ -126,6 +112,7 @@ function Set-TargetResource [System.String] $Identity, + # DEPRECATED [Parameter()] [System.String[]] $Users, @@ -204,6 +191,7 @@ function Test-TargetResource [System.String] $Identity, + # DEPRECATED [Parameter()] [System.String[]] $Users, @@ -255,6 +243,7 @@ function Test-TargetResource Write-Verbose -Message "Target Values: $(Convert-M365DscHashtableToString -Hashtable $PSBoundParameters)" $ValuesToCheck = $PSBoundParameters + $ValuesToCheck.Remove("Users") | Out-Null $TestResult = Test-M365DSCParameterState -CurrentValues $CurrentValues ` -Source $($MyInvocation.MyCommand.Source) ` diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_TeamsUpgradePolicy/MSFT_TeamsUpgradePolicy.schema.mof b/Modules/Microsoft365DSC/DSCResources/MSFT_TeamsUpgradePolicy/MSFT_TeamsUpgradePolicy.schema.mof index dcd1b3df49..6168d86186 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_TeamsUpgradePolicy/MSFT_TeamsUpgradePolicy.schema.mof +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_TeamsUpgradePolicy/MSFT_TeamsUpgradePolicy.schema.mof @@ -2,7 +2,7 @@ class MSFT_TeamsUpgradePolicy : OMI_BaseResource { [Key, Description("Identity of the Teams Upgrade Policy.")] String Identity; - [Write, Description("List of users that will be granted the Upgrade Policy to. Use value * to apply the policy globally.")] String Users[]; + [Write, Description("DEPRECATED. Use the TeamsUserPolicyAssignment resource instead.")] String Users[]; [Write, Description("Specifies whether to move existing Skype for Business meetings organized by the user to Teams. This parameter can only be true if the mode of the specified policy instance is either TeamsOnly or SfBWithTeamsCollabAndMeetings, and if the policy instance is being granted to a specific user. It not possible to trigger meeting migration when granting TeamsUpgradePolicy to the entire tenant.")] Boolean MigrateMeetingsToTeams; [Write, Description("Credentials of the Teams Admin"), EmbeddedInstance("MSFT_Credential")] string Credential; [Write, Description("Id of the Azure Active Directory application to authenticate with.")] String ApplicationId; diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_TeamsUserPolicyAssignment/MSFT_TeamsUserPolicyAssignment.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_TeamsUserPolicyAssignment/MSFT_TeamsUserPolicyAssignment.psm1 index ce927c2248..76c6feb52f 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_TeamsUserPolicyAssignment/MSFT_TeamsUserPolicyAssignment.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_TeamsUserPolicyAssignment/MSFT_TeamsUserPolicyAssignment.psm1 @@ -143,31 +143,164 @@ function Get-TargetResource Write-Verbose -Message "User Policy Assignment not found for $User" return $null } + + $CallingLineIdentityValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'CallingLineIdentity'}).PolicyName + if ([System.String]::IsNullOrEmpty($CallingLineIdentityValue)) + { + $CallingLineIdentityValue = 'Global' + } + + $ExternalAccessPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'ExternalAccessPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($ExternalAccessPolicyValue)) + { + $ExternalAccessPolicyValue = 'Global' + } + + $OnlineVoicemailPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'OnlineVoicemailPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($OnlineVoicemailPolicyValue)) + { + $OnlineVoicemailPolicyValue = 'Global' + } + + $OnlineVoiceRoutingPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'OnlineVoiceRoutingPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($OnlineVoiceRoutingPolicyValue)) + { + $OnlineVoiceRoutingPolicyValue = 'Global' + } + + $TeamsAppPermissionPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsAppPermissionPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsAppPermissionPolicyValue)) + { + $TeamsAppPermissionPolicyValue = 'Global' + } + + $TeamsAppSetupPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsAppSetupPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsAppSetupPolicyValue)) + { + $TeamsAppSetupPolicyValue = 'Global' + } + + $TeamsAudioConferencingPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsAudioConferencingPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsAudioConferencingPolicyValue)) + { + $TeamsAudioConferencingPolicyValue = 'Global' + } + + $TeamsCallHoldPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsCallHoldPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsCallHoldPolicyValue)) + { + $TeamsCallHoldPolicyValue = 'Global' + } + + $TeamsCallingPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsCallingPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsCallingPolicyValue)) + { + $TeamsCallingPolicyValue = 'Global' + } + + $TeamsCallParkPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsCallParkPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsCallParkPolicyValue)) + { + $TeamsCallParkPolicyValue = 'Global' + } + + $TeamsChannelsPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsChannelsPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsChannelsPolicyValue)) + { + $TeamsChannelsPolicyValue = 'Global' + } + + $TeamsEmergencyCallingPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsEmergencyCallingPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsEmergencyCallingPolicyValue)) + { + $TeamsEmergencyCallingPolicyValue = 'Global' + } + + $TeamsEmergencyCallRoutingPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsEmergencyCallRoutingPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsEmergencyCallRoutingPolicyValue)) + { + $TeamsEmergencyCallRoutingPolicyValue = 'Global' + } + + $TeamsEnhancedEncryptionPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsEnhancedEncryptionPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsEnhancedEncryptionPolicyValue)) + { + $TeamsEnhancedEncryptionPolicyValue = 'Global' + } + + $TeamsEventsPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsEventsPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsEventsPolicyValue)) + { + $TeamsEventsPolicyValue = 'Global' + } + + $TeamsMeetingBroadcastPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsMeetingBroadcastPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsMeetingBroadcastPolicyValue)) + { + $TeamsMeetingBroadcastPolicyValue = 'Global' + } + + $TeamsMeetingPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsMeetingPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsMeetingPolicyValue)) + { + $TeamsMeetingPolicyValue = 'Global' + } + + $TeamsMessagingPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsMessagingPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsMessagingPolicyValue)) + { + $TeamsMessagingPolicyValue = 'Global' + } + + $TeamsMobilityPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsMobilityPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsMobilityPolicyValue)) + { + $TeamsMobilityPolicyValue = 'Global' + } + + $TeamsUpdateManagementPolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsUpdateManagementPolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsUpdateManagementPolicyValue)) + { + $TeamsUpdateManagementPolicyValue = 'Global' + } + + $TeamsUpgradePolicyValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsUpgradePolicy'}).PolicyName + if ([System.String]::IsNullOrEmpty($TeamsUpgradePolicyValue)) + { + $TeamsUpgradePolicyValue = 'Global' + } + + $TenantDialPlanValue = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TenantDialPlan'}).PolicyName + if ([System.String]::IsNullOrEmpty($TenantDialPlanValue)) + { + $TenantDialPlanValue = 'Global' + } + Write-Verbose -Message "Found Policy Assignment for user {$User}" return @{ User = $User - CallingLineIdentity = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'CallingLineIdentity'}).PolicyName - ExternalAccessPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'ExternalAccessPolicy'}).PolicyName - OnlineVoicemailPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'OnlineVoicemailPolicy'}).PolicyName - OnlineVoiceRoutingPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'OnlineVoiceRoutingPolicy'}).PolicyName - TeamsAppPermissionPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsAppPermissionPolicy'}).PolicyName - TeamsAppSetupPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsAppSetupPolicy'}).PolicyName - TeamsAudioConferencingPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsAudioConferencingPolicy'}).PolicyName - TeamsCallHoldPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsCallHoldPolicy'}).PolicyName - TeamsCallingPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsCallingPolicy'}).PolicyName - TeamsCallParkPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsCallParkPolicy'}).PolicyName - TeamsChannelsPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsChannelsPolicy'}).PolicyName - TeamsEmergencyCallingPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsEmergencyCallingPolicy'}).PolicyName - TeamsEmergencyCallRoutingPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsEmergencyCallRoutingPolicy'}).PolicyName - TeamsEnhancedEncryptionPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsEnhancedEncryptionPolicy'}).PolicyName - TeamsEventsPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsEventsPolicy'}).PolicyName - TeamsMeetingBroadcastPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsMeetingBroadcastPolicy'}).PolicyName - TeamsMeetingPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsMeetingPolicy'}).PolicyName - TeamsMessagingPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsMessagingPolicy'}).PolicyName - TeamsMobilityPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsMobilityPolicy'}).PolicyName - TeamsUpdateManagementPolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsUpdateManagementPolicy'}).PolicyName - TeamsUpgradePolicy = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TeamsUpgradePolicy'}).PolicyName - TenantDialPlan = ($assignment | Where-Object -FilterScript {$_.PolicyType -eq 'TenantDialPlan'}).PolicyName + CallingLineIdentity = $CallingLineIdentityValue + ExternalAccessPolicy = $ExternalAccessPolicyValue + OnlineVoicemailPolicy = $OnlineVoicemailPolicyValue + OnlineVoiceRoutingPolicy = $OnlineVoiceRoutingPolicyValue + TeamsAppPermissionPolicy = $TeamsAppPermissionPolicyValue + TeamsAppSetupPolicy = $TeamsAppSetupPolicyValue + TeamsAudioConferencingPolicy = $TeamsAudioConferencingPolicyValue + TeamsCallHoldPolicy = $TeamsCallHoldPolicyValue + TeamsCallingPolicy = $TeamsCallingPolicyValue + TeamsCallParkPolicy = $TeamsCallParkPolicyValue + TeamsChannelsPolicy = $TeamsChannelsPolicyValue + TeamsEmergencyCallingPolicy = $TeamsEmergencyCallingPolicyValue + TeamsEmergencyCallRoutingPolicy = $TeamsEmergencyCallRoutingPolicyValue + TeamsEnhancedEncryptionPolicy = $TeamsEnhancedEncryptionPolicyValue + TeamsEventsPolicy = $TeamsEventsPolicyValue + TeamsMeetingBroadcastPolicy = $TeamsMeetingBroadcastPolicyValue + TeamsMeetingPolicy = $TeamsMeetingPolicyValue + TeamsMessagingPolicy = $TeamsMessagingPolicyValue + TeamsMobilityPolicy = $TeamsMobilityPolicyValue + TeamsUpdateManagementPolicy = $TeamsUpdateManagementPolicyValue + TeamsUpgradePolicy = $TeamsUpgradePolicyValue + TenantDialPlan = $TenantDialPlanValue Credential = $Credential ApplicationId = $ApplicationId TenantId = $TenantId @@ -324,116 +457,205 @@ function Set-TargetResource $ConnectionMode = New-M365DSCConnection -Workload 'MicrosoftTeams' -InboundParameters $PSBoundParameters + $currentInstance = Get-TargetResource @PSBoundParameters try { - if ($null -ne $CallingLineIdentity) + if ($null -ne $CallingLineIdentity -and $CallingLineIdentity -ne $currentInstance.CallingLineIdentity) { Write-Verbose -Message "Assigning the Call Line Identity Policy {$CallingLineIdentity} to user {$User}" + if ($CallingLineIdentity -eq 'Global') + { + $CallingLineIdentity = $null + } Grant-CsCallingLineIdentity -Identity $User -PolicyName $CallingLineIdentity | Out-Null } - if ($null -ne $ExternalAccessPolicy) + if ($null -ne $ExternalAccessPolicy -and $ExternalAccessPolicy -ne $currentInstance.ExternalAccessPolicy) { Write-Verbose -Message "Assigning the External Access Policy {$ExternalAccessPolicy} to user {$User}" - Grant-CsExternalAccessPolicy -Identity $User -PolicyName $CallingLineIdentity | Out-Null + if ($ExternalAccessPolicy -eq 'Global') + { + $ExternalAccessPolicy = $null + } + Grant-CsExternalAccessPolicy -Identity $User -PolicyName $ExternalAccessPolicy | Out-Null } - if ($null -ne $OnlineVoicemailPolicy) + if ($null -ne $OnlineVoicemailPolicy -and $OnlineVoicemailPolicy -ne $currentInstance.OnlineVoicemailPolicy) { Write-Verbose -Message "Assigning the Online Voicemail Policy {$OnlineVoicemailPolicy} to user {$User}" + if ($OnlineVoicemailPolicy -eq 'Global') + { + $OnlineVoicemailPolicy = $null + } Grant-CsOnlineVoicemailPolicy -Identity $User -PolicyName $OnlineVoicemailPolicy | Out-Null } - if ($null -ne $OnlineVoiceRoutingPolicy) + if ($null -ne $OnlineVoiceRoutingPolicy -and $OnlineVoiceRoutingPolicy -ne $currentInstance.OnlineVoiceRoutingPolicy) { Write-Verbose -Message "Assigning the Online Voice Routing Policy {$OnlineVoiceRoutingPolicy} to user {$User}" + if ($OnlineVoiceRoutingPolicy -eq 'Global') + { + $OnlineVoiceRoutingPolicy = $null + } Grant-CsOnlineVoiceRoutingPolicy -Identity $User -PolicyName $OnlineVoiceRoutingPolicy | Out-Null } - if ($null -ne $TeamsAppPermissionPolicy) + if ($null -ne $TeamsAppPermissionPolicy -and $TeamsAppPermissionPolicy -ne $currentInstance.TeamsAppPermissionPolicy) { Write-Verbose -Message "Assigning the Apps Permission Policy {$TeamsAppPermissionPolicy} to user {$User}" + if ($TeamsAppPermissionPolicy -eq 'Global') + { + $TeamsAppPermissionPolicy = $null + } Grant-CsTeamsAppPermissionPolicy -Identity $User -PolicyName $TeamsAppPermissionPolicy | Out-Null } - if ($null -ne $TeamsAppSetupPolicy) + if ($null -ne $TeamsAppSetupPolicy -and $TeamsAppSetupPolicy -ne $currentInstance.TeamsAppSetupPolicy) { Write-Verbose -Message "Assigning the Apps Setup Policy {$TeamsAppSetupPolicy} to user {$User}" + if ($TeamsAppSetupPolicy -eq 'Global') + { + $TeamsAppSetupPolicy = $null + } Grant-CsTeamsAppSetupPolicy -Identity $User -PolicyName $TeamsAppSetupPolicy | Out-Null } - if ($null -ne $TeamsAudioConferencingPolicy) + if ($null -ne $TeamsAudioConferencingPolicy -and $TeamsAudioConferencingPolicy -ne $currentInstance.TeamsAudioConferencingPolicy) { Write-Verbose -Message "Assigning the Audio COnferencing Policy {$TeamsAudioConferencingPolicy} to user {$User}" + if ($TeamsAudioConferencingPolicy -eq 'Global') + { + $TeamsAudioConferencingPolicy = $null + } Grant-CsTeamsAudioConferencingPolicy -Identity $User -PolicyName $TeamsAudioConferencingPolicy | Out-Null } - if ($null -ne $TeamsCallHoldPolicy) + if ($null -ne $TeamsCallHoldPolicy -and $TeamsCallHoldPolicy -ne $currentInstance.TeamsCallHoldPolicy) { Write-Verbose -Message "Assigning the Call Hold Policy {$TeamsCallHoldPolicy} to user {$User}" + if ($TeamsCallHoldPolicy -eq 'Global') + { + $TeamsCallHoldPolicy = $null + } Grant-CsTeamsCallHoldPolicy -Identity $User -PolicyName $TeamsCallHoldPolicy | Out-Null } - if ($null -ne $TeamsCallingPolicy) + if ($null -ne $TeamsCallingPolicy -and $TeamsCallingPolicy -ne $currentInstance.TeamsCallingPolicy) { - Write-Verbose -Message "Assigning the Calling Policy {$TeamsCallingPolicy} to user {$User}" + Write-Verbose -Message "Assigning the Calling Policy {$TeamsCallParkPolicy} to user {$User}" + if ($TeamsCallParkPolicy -eq 'Global') + { + $TeamsCallParkPolicy = $null + } Grant-CsTeamsCallingPolicy -Identity $User -PolicyName $TeamsCallingPolicy | Out-Null } - if ($null -ne $TeamsCallParkPolicy) + if ($null -ne $TeamsCallParkPolicy -and $TeamsCallParkPolicy -ne $currentInstance.TeamsCallParkPolicy) { Write-Verbose -Message "Assigning the Call Park Policy {$TeamsCallParkPolicy} to user {$User}" + if ($TeamsCallParkPolicy -eq 'Global') + { + $TeamsCallParkPolicy = $null + } Grant-CsTeamsCallParkPolicy -Identity $User -PolicyName $TeamsCallParkPolicy | Out-Null } - if ($null -ne $TeamsChannelsPolicy) + if ($null -ne $TeamsChannelsPolicy -and $TeamsChannelsPolicy -ne $currentInstance.TeamsChannelsPolicy) { Write-Verbose -Message "Assigning the Channels Policy {$TeamsChannelsPolicy} to user {$User}" + if ($TeamsChannelsPolicy -eq 'Global') + { + $TeamsChannelsPolicy = $null + } Grant-CsTeamsChannelsPolicy -Identity $User -PolicyName $TeamsChannelsPolicy | Out-Null } - if ($null -ne $TeamsEmergencyCallingPolicy) + if ($null -ne $TeamsEmergencyCallingPolicy -and $TeamsEmergencyCallingPolicy -ne $currentInstance.TeamsEmergencyCallingPolicy) { Write-Verbose -Message "Assigning the Emergency Calling Policy {$TeamsEmergencyCallingPolicy} to user {$User}" + if ($TeamsEmergencyCallingPolicy -eq 'Global') + { + $TeamsEmergencyCallingPolicy = $null + } Grant-CsTeamsEmergencyCallingPolicy -Identity $User -PolicyName $TeamsEmergencyCallingPolicy | Out-Null } - if ($null -ne $TeamsEmergencyCallRoutingPolicy) + if ($null -ne $TeamsEmergencyCallRoutingPolicy -and $TeamsEmergencyCallRoutingPolicy -ne $currentInstance.TeamsEmergencyCallRoutingPolicy) { Write-Verbose -Message "Assigning the Emergency Call Routing Policy {$TeamsEmergencyCallRoutingPolicy} to user {$User}" + if ($TeamsEmergencyCallRoutingPolicy -eq 'Global') + { + $TeamsEmergencyCallRoutingPolicy = $null + } Grant-CsTeamsEmergencyCallRoutingPolicy -Identity $User -PolicyName $TeamsEmergencyCallRoutingPolicy | Out-Null } - if ($null -ne $TeamsEnhancedEncryptionPolicy) + if ($null -ne $TeamsEnhancedEncryptionPolicy -and $TeamsEnhancedEncryptionPolicy -ne $currentInstance.TeamsEnhancedEncryptionPolicy) { Write-Verbose -Message "Assigning the Enhanced Encryption Policy {$TeamsEnhancedEncryptionPolicy} to user {$User}" + if ($TeamsEnhancedEncryptionPolicy -eq 'Global') + { + $TeamsEnhancedEncryptionPolicy = $null + } Grant-CsTeamsEnhancedEncryptionPolicy -Identity $User -PolicyName $TeamsEnhancedEncryptionPolicy | Out-Null } - if ($null -ne $TeamsEventsPolicy) + if ($null -ne $TeamsEventsPolicy -and $TeamsEventsPolicy -ne $currentInstance.TeamsEventsPolicy) { Write-Verbose -Message "Assigning the Events Policy {$TeamsEventsPolicy} to user {$User}" + if ($TeamsEventsPolicy -eq 'Global') + { + $TeamsEventsPolicy = $null + } Grant-CsTeamsEventsPolicy -Identity $User -PolicyName $TeamsEventsPolicy | Out-Null } - if ($null -ne $TeamsMeetingBroadcastPolicy) + if ($null -ne $TeamsMeetingBroadcastPolicy -and $TeamsMeetingBroadcastPolicy -ne $currentInstance.TeamsMeetingBroadcastPolicy) { Write-Verbose -Message "Assigning the Meeting Broadcast Policy {$TeamsMeetingBroadcastPolicy} to user {$User}" + if ($TeamsMeetingBroadcastPolicy -eq 'Global') + { + $TeamsMeetingBroadcastPolicy = $null + } Grant-CsTeamsMeetingBroadcastPolicy -Identity $User -PolicyName $TeamsMeetingBroadcastPolicy | Out-Null } - if ($null -ne $TeamsMeetingPolicy) + if ($null -ne $TeamsMeetingPolicy -and $TeamsMeetingPolicy -ne $currentInstance.TeamsMeetingPolicy) { Write-Verbose -Message "Assigning the Meeting Policy {$TeamsMeetingPolicy} to user {$User}" + if ($TeamsMeetingPolicy -eq 'Global') + { + $TeamsMeetingPolicy = $null + } Grant-CsTeamsMeetingPolicy -Identity $User -PolicyName $TeamsMeetingPolicy | Out-Null } - if ($null -ne $TeamsMessagingPolicy) + if ($null -ne $TeamsMessagingPolicy -and $TeamsMessagingPolicy -ne $currentInstance.TeamsMessagingPolicy) { Write-Verbose -Message "Assigning the Messaging Policy {$TeamsMessagingPolicy} to user {$User}" + if ($TeamsMessagingPolicy -eq 'Global') + { + $TeamsMessagingPolicy = $null + } Grant-CsTeamsMessagingPolicy -Identity $User -PolicyName $TeamsMessagingPolicy | Out-Null } - if ($null -ne $TeamsMobilityPolicy) + if ($null -ne $TeamsMobilityPolicy -and $TeamsMobilityPolicy -ne $currentInstance.TeamsMobilityPolicy) { Write-Verbose -Message "Assigning the Mobility Policy {$TeamsMobilityPolicy} to user {$User}" + if ($TeamsMobilityPolicy -eq 'Global') + { + $TeamsMobilityPolicy = $null + } Grant-CsTeamsMobilityPolicy -Identity $User -PolicyName $TeamsMobilityPolicy | Out-Null } - if ($null -ne $TeamsUpdateManagementPolicy) + if ($null -ne $TeamsUpdateManagementPolicy -and $TeamsUpdateManagementPolicy -ne $currentInstance.TeamsUpdateManagementPolicy) { Write-Verbose -Message "Assigning the Update Management Policy {$TeamsUpdateManagementPolicy} to user {$User}" + if ($TeamsUpdateManagementPolicy -eq 'Global') + { + $TeamsUpdateManagementPolicy = $null + } Grant-CsTeamsUpdateManagementPolicy -Identity $User -PolicyName $TeamsUpdateManagementPolicy | Out-Null } - if ($null -ne $TeamsUpgradePolicy) + if ($null -ne $TeamsUpgradePolicy -and $TeamsUpgradePolicy -ne $currentInstance.TeamsUpgradePolicy) { Write-Verbose -Message "Assigning the Upgrade Policy {$TeamsUpgradePolicy} to user {$User}" + if ($TeamsUpgradePolicy -eq 'Global') + { + $TeamsUpgradePolicy = $null + } Grant-CsTeamsUpgradePolicy -Identity $User -PolicyName $TeamsUpgradePolicy | Out-Null } - if ($null -ne $TenantDialPlan) + if ($null -ne $TenantDialPlan -and $TenantDialPlan -ne $currentInstance.TenantDialPlan) { Write-Verbose -Message "Assigning the Tenant Dial Plan {$TenantDialPlan} to user {$User}" + if ($TenantDialPlan -eq 'Global') + { + $TenantDialPlan = $null + } Grant-CsTenantDialPlan -Identity $User -PolicyName $TenantDialPlan | Out-Null } } diff --git a/Modules/Microsoft365DSC/Examples/Resources/TeamsUpgradePolicy/1-AssignUsersToTeamsUpgradePolicy.ps1 b/Modules/Microsoft365DSC/Examples/Resources/TeamsUpgradePolicy/1-AssignUsersToTeamsUpgradePolicy.ps1 index bfefa45dcd..921a068beb 100644 --- a/Modules/Microsoft365DSC/Examples/Resources/TeamsUpgradePolicy/1-AssignUsersToTeamsUpgradePolicy.ps1 +++ b/Modules/Microsoft365DSC/Examples/Resources/TeamsUpgradePolicy/1-AssignUsersToTeamsUpgradePolicy.ps1 @@ -16,7 +16,6 @@ Configuration Example TeamsUpgradePolicy 'ConfigureIslandsPolicy' { Identity = 'Islands' - Users = @("John.Smith@contoso.com", "Nik.Charlebois@contoso.com") MigrateMeetingsToTeams = $true Credential = $Credscredential } diff --git a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 index 0eae31dd77..ed4be1270b 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 @@ -3829,6 +3829,10 @@ function Get-M365DSCExportContentForResource { $primaryKey = $Results.UserPrincipalName } + elseif ($Keys.Contains('User')) + { + $primaryKey = $Results.User + } $instanceName = $ResourceName if (-not [System.String]::IsNullOrEmpty($primaryKey)) diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.TeamsUpgradePolicy.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.TeamsUpgradePolicy.Tests.ps1 index 04217fe254..c8fe4e0e46 100644 --- a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.TeamsUpgradePolicy.Tests.ps1 +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.TeamsUpgradePolicy.Tests.ps1 @@ -49,7 +49,6 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { BeforeAll { $testParams = @{ Identity = 'Test Policy' - Users = @('john.smith@contoso.onmicrosoft.com') MigrateMeetingsToTeams = $false Credential = $Credential } @@ -64,46 +63,10 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } } - Context -Name 'When the policy already exists and is NOT in the Desired State' -Fixture { - BeforeAll { - $testParams = @{ - Identity = 'Test Policy' - Users = @('john.smith@contoso.onmicrosoft.com') - MigrateMeetingsToTeams = $false - Credential = $Credential - } - - Mock -CommandName Get-CsTeamsUpgradePolicy -MockWith { - return @{ - Identity = 'Test Policy' - Description = 'This is a configuration drift' - NotifySfBUsers = $false - } - } - - Mock -CommandName Get-CsOnlineUser -MockWith { - return @{ - UserPrincipalName = 'Bob.Houle@contoso.onmicrosoft.com' - TeamsUpgradePolicy = 'Global' - } - } - } - - It 'Should return false from the Test method' { - Test-TargetResource @testParams | Should -Be $false - } - - It 'Should update the policy from the Set method' { - Set-TargetResource @testParams - Should -Invoke -CommandName Grant-CsTeamsUpgradePolicy -Exactly 1 - } - } - Context -Name 'When the policy already exists and IS in the Desired State' -Fixture { BeforeAll { $testParams = @{ Identity = 'Islands' - Users = @('john.smith@contoso.onmicrosoft.com') MigrateMeetingsToTeams = $false Credential = $Credential } @@ -115,13 +78,6 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { NotifySfBUsers = $false } } - - Mock -CommandName Get-CsOnlineUser -MockWith { - return @{ - UserPrincipalName = 'John.Smith@contoso.onmicrosoft.com' - TeamsUpgradePolicy = 'Islands' - } - } } It 'Should return true from the Test method' { @@ -144,13 +100,6 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { NotifySfBUsers = $false } } - - Mock -CommandName Get-CsOnlineUser -MockWith { - return @{ - UserPrincipalName = 'John.Smith@contoso.onmicrosoft.com' - TeamsUpgradePolicy = 'Islands' - } - } } It 'Should Reverse Engineer resource from the Export method' {