Skip to content

Commit d0fe6be

Browse files
Merge pull request #1203 from Ren-Roros-Digital/MessagingPolicy
feat: New Global Teams Messaging Policy standard
2 parents d91c4ff + 92e68cb commit d0fe6be

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
Function Invoke-CIPPStandardTeamsMessagingPolicy {
2+
<#
3+
.FUNCTIONALITY
4+
Internal
5+
.COMPONENT
6+
(APIName) TeamsMessagingPolicy
7+
.NOTES
8+
UPDATECOMMENTBLOCK
9+
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
10+
.LINK
11+
https://docs.cipp.app/user-documentation/tenant/standards/edit-standards
12+
#>
13+
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'TeamsMessagingPolicy'
14+
15+
param($Tenant, $Settings)
16+
$CurrentState = New-TeamsRequest -TenantFilter $Tenant -Cmdlet 'Get-CsTeamsMessagingPolicy' -CmdParams @{Identity = 'Global' }
17+
18+
if ($null -eq $Settings.AllowOwnerDeleteMessage) { $Settings.AllowOwnerDeleteMessage = $CurrentState.AllowOwnerDeleteMessage }
19+
if ($null -eq $Settings.AllowUserDeleteMessage) { $Settings.AllowUserDeleteMessage = $CurrentState.AllowUserDeleteMessage }
20+
if ($null -eq $Settings.AllowUserEditMessage) { $Settings.AllowUserEditMessage = $CurrentState.AllowUserEditMessage }
21+
if ($null -eq $Settings.AllowUserDeleteChat) { $Settings.AllowUserDeleteChat = $CurrentState.AllowUserDeleteChat }
22+
if ($null -eq $Settings.ReadReceiptsEnabledType) { $Settings.ReadReceiptsEnabledType = $CurrentState.ReadReceiptsEnabledType }
23+
if ($null -eq $Settings.CreateCustomEmojis) { $Settings.CreateCustomEmojis = $CurrentState.CreateCustomEmojis }
24+
if ($null -eq $Settings.DeleteCustomEmojis) { $Settings.DeleteCustomEmojis = $CurrentState.DeleteCustomEmojis }
25+
if ($null -eq $Settings.AllowSecurityEndUserReporting) { $Settings.AllowSecurityEndUserReporting = $CurrentState.AllowSecurityEndUserReporting }
26+
if ($null -eq $Settings.AllowCommunicationComplianceEndUserReporting) { $Settings.AllowCommunicationComplianceEndUserReporting = $CurrentState.AllowCommunicationComplianceEndUserReporting }
27+
28+
$StateIsCorrect = ($CurrentState.AllowOwnerDeleteMessage -eq $Settings.AllowOwnerDeleteMessage) -and
29+
($CurrentState.AllowUserDeleteMessage -eq $Settings.AllowUserDeleteMessage) -and
30+
($CurrentState.AllowUserEditMessage -eq $Settings.AllowUserEditMessage) -and
31+
($CurrentState.AllowUserDeleteChat -eq $Settings.AllowUserDeleteChat) -and
32+
($CurrentState.ReadReceiptsEnabledType -eq $Settings.ReadReceiptsEnabledType) -and
33+
($CurrentState.CreateCustomEmojis -eq $Settings.CreateCustomEmojis) -and
34+
($CurrentState.DeleteCustomEmojis -eq $Settings.DeleteCustomEmojis) -and
35+
($CurrentState.AllowSecurityEndUserReporting -eq $Settings.AllowSecurityEndUserReporting) -and
36+
($CurrentState.AllowCommunicationComplianceEndUserReporting -eq $Settings.AllowCommunicationComplianceEndUserReporting)
37+
38+
if ($Settings.remediate -eq $true) {
39+
if ($StateIsCorrect -eq $true) {
40+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Global Teams Messaging policy already configured.' -sev Info
41+
} else {
42+
$cmdparams = @{
43+
Identity = 'Global'
44+
AllowOwnerDeleteMessage = $Settings.AllowOwnerDeleteMessage
45+
AllowUserDeleteMessage = $Settings.AllowUserDeleteMessage
46+
AllowUserEditMessage = $Settings.AllowUserEditMessage
47+
AllowUserDeleteChat = $Settings.AllowUserDeleteChat
48+
ReadReceiptsEnabledType = $Settings.ReadReceiptsEnabledType
49+
CreateCustomEmojis = $Settings.CreateCustomEmojis
50+
DeleteCustomEmojis = $Settings.DeleteCustomEmojis
51+
AllowSecurityEndUserReporting = $Settings.AllowSecurityEndUserReporting
52+
AllowCommunicationComplianceEndUserReporting = $Settings.AllowCommunicationComplianceEndUserReporting
53+
}
54+
55+
try {
56+
New-TeamsRequest -TenantFilter $Tenant -Cmdlet 'Set-CsTeamsMessagingPolicy' -CmdParams $cmdparams
57+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Updated global Teams messaging policy' -sev Info
58+
} catch {
59+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
60+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to configure global Teams messaging policy." -sev Error -LogData $ErrorMessage
61+
}
62+
}
63+
}
64+
65+
if ($Settings.alert -eq $true) {
66+
if ($StateIsCorrect -eq $true) {
67+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Global Teams messaging policy is configured correctly.' -sev Info
68+
} else {
69+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Global Teams messaging policy is not configured correctly.' -sev Alert
70+
}
71+
}
72+
73+
if ($Setings.report -eq $true) {
74+
Add-CIPPBPAField -FieldName 'TeamsMessagingPolicy' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $Tenant
75+
}
76+
}

0 commit comments

Comments
 (0)