Skip to content

Commit f4dd2a7

Browse files
committed
fix(standards): default untoggled Teams switches to $false instead of sending null
Untoggled "switch" inputs are omitted from a standard's settings, so TeamsGlobalMeetingPolicy, TeamsExternalFileSharing, and TeamsFederationConfiguration serialized null booleans to the Teams ConfigApi, which rejects the write with 400 "Error converting value {null} to type 'System.Boolean'". The null also poisoned the $StateIsCorrect comparison ($CurrentState.X -eq $null is never true), so affected tenants reported non-compliant and failed remediation on every run. Coalesce each switch to $false (the CIS recommended value, matching the convention in TeamsExternalAccessPolicy/TeamsGuestAccess/ TeamsEmailIntegration) and use the coalesced variable in the state comparison, remediation payload, and report expected values. In TeamsExternalFileSharing the existing "?? $false" was dead code because -eq binds tighter than ??.
1 parent 5a08c2c commit f4dd2a7

3 files changed

Lines changed: 49 additions & 33 deletions

File tree

Modules/CIPPStandards/Public/Standards/Invoke-CIPPStandardTeamsExternalFileSharing.ps1

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,30 @@ function Invoke-CIPPStandardTeamsExternalFileSharing {
5858
return
5959
}
6060

61-
$StateIsCorrect = ($CurrentState.AllowGoogleDrive -eq $Settings.AllowGoogleDrive ?? $false ) -and
62-
($CurrentState.AllowShareFile -eq $Settings.AllowShareFile ?? $false ) -and
63-
($CurrentState.AllowBox -eq $Settings.AllowBox ?? $false ) -and
64-
($CurrentState.AllowDropBox -eq $Settings.AllowDropBox ?? $false ) -and
65-
($CurrentState.AllowEgnyte -eq $Settings.AllowEgnyte ?? $false )
61+
# Untoggled switches are absent from the settings; default them to $false so we never send null to the ConfigApi
62+
$AllowGoogleDrive = $Settings.AllowGoogleDrive ?? $false
63+
$AllowShareFile = $Settings.AllowShareFile ?? $false
64+
$AllowBox = $Settings.AllowBox ?? $false
65+
$AllowDropBox = $Settings.AllowDropBox ?? $false
66+
$AllowEgnyte = $Settings.AllowEgnyte ?? $false
67+
68+
$StateIsCorrect = ($CurrentState.AllowGoogleDrive -eq $AllowGoogleDrive) -and
69+
($CurrentState.AllowShareFile -eq $AllowShareFile) -and
70+
($CurrentState.AllowBox -eq $AllowBox) -and
71+
($CurrentState.AllowDropBox -eq $AllowDropBox) -and
72+
($CurrentState.AllowEgnyte -eq $AllowEgnyte)
6673

6774
if ($Settings.remediate -eq $true) {
6875
if ($StateIsCorrect -eq $true) {
6976
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Teams External File Sharing already set.' -sev Info
7077
} else {
7178
$cmdParams = @{
7279
Identity = 'Global'
73-
AllowGoogleDrive = $Settings.AllowGoogleDrive
74-
AllowShareFile = $Settings.AllowShareFile
75-
AllowBox = $Settings.AllowBox
76-
AllowDropBox = $Settings.AllowDropBox
77-
AllowEgnyte = $Settings.AllowEgnyte
80+
AllowGoogleDrive = $AllowGoogleDrive
81+
AllowShareFile = $AllowShareFile
82+
AllowBox = $AllowBox
83+
AllowDropBox = $AllowDropBox
84+
AllowEgnyte = $AllowEgnyte
7885
}
7986

8087
try {
@@ -107,11 +114,11 @@ function Invoke-CIPPStandardTeamsExternalFileSharing {
107114
AllowEgnyte = $CurrentState.AllowEgnyte
108115
}
109116
$ExpectedValue = @{
110-
AllowGoogleDrive = $Settings.AllowGoogleDrive
111-
AllowShareFile = $Settings.AllowShareFile
112-
AllowBox = $Settings.AllowBox
113-
AllowDropBox = $Settings.AllowDropBox
114-
AllowEgnyte = $Settings.AllowEgnyte
117+
AllowGoogleDrive = $AllowGoogleDrive
118+
AllowShareFile = $AllowShareFile
119+
AllowBox = $AllowBox
120+
AllowDropBox = $AllowDropBox
121+
AllowEgnyte = $AllowEgnyte
115122
}
116123
Set-CIPPStandardsCompareField -FieldName 'standards.TeamsExternalFileSharing' -CurrentValue $CurrentValue -ExpectedValue $ExpectedValue -Tenant $Tenant
117124
}

Modules/CIPPStandards/Public/Standards/Invoke-CIPPStandardTeamsFederationConfiguration.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ function Invoke-CIPPStandardTeamsFederationConfiguration {
5858
# Allow specific external -> AllowedDomains = @{ AllowList = @(list) }
5959
# Block specific external -> AllowedDomains = @{ AllowList = @() } + BlockedDomains = @(list)
6060
$DomainControl = $Settings.DomainControl.value ?? $Settings.DomainControl
61+
# An untoggled switch is absent from the settings; default it to $false so we never send null to the ConfigApi
62+
$AllowTeamsConsumer = $Settings.AllowTeamsConsumer ?? $false
6163
$AllowedDomainsAsAList = @()
6264
$BlockedDomains = @()
6365
switch ($DomainControl) {
@@ -137,7 +139,7 @@ function Invoke-CIPPStandardTeamsFederationConfiguration {
137139

138140
$ExpectedBlockedDomains = $BlockedDomains ?? @()
139141

140-
$StateIsCorrect = ($CurrentState.AllowTeamsConsumer -eq $Settings.AllowTeamsConsumer) -and
142+
$StateIsCorrect = ($CurrentState.AllowTeamsConsumer -eq $AllowTeamsConsumer) -and
141143
($CurrentState.AllowFederatedUsers -eq $AllowFederatedUsers) -and
142144
$AllowedDomainsMatches -and
143145
$BlockedDomainsMatches
@@ -148,7 +150,7 @@ function Invoke-CIPPStandardTeamsFederationConfiguration {
148150
} else {
149151
$cmdParams = @{
150152
Identity = 'Global'
151-
AllowTeamsConsumer = $Settings.AllowTeamsConsumer
153+
AllowTeamsConsumer = $AllowTeamsConsumer
152154
AllowFederatedUsers = $AllowFederatedUsers
153155
AllowedDomains = $AllowedDomainsPayload
154156
BlockedDomains = @($BlockedDomains)
@@ -214,7 +216,7 @@ function Invoke-CIPPStandardTeamsFederationConfiguration {
214216
BlockedDomains = $CurrentBlockedDomainsForReport
215217
}
216218
$ExpectedValue = @{
217-
AllowTeamsConsumer = $Settings.AllowTeamsConsumer
219+
AllowTeamsConsumer = $AllowTeamsConsumer
218220
AllowFederatedUsers = $AllowFederatedUsers
219221
AllowedDomains = $ExpectedAllowedDomainsForReport
220222
BlockedDomains = $ExpectedBlockedDomainsForReport

Modules/CIPPStandards/Public/Standards/Invoke-CIPPStandardTeamsGlobalMeetingPolicy.ps1

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,21 @@ function Invoke-CIPPStandardTeamsGlobalMeetingPolicy {
6969
$DesignatedPresenterRoleMode = $Settings.DesignatedPresenterRoleMode.value ?? $Settings.DesignatedPresenterRoleMode
7070
$AutoAdmittedUsers = $Settings.AutoAdmittedUsers.value ?? $Settings.AutoAdmittedUsers ?? $CurrentState.AutoAdmittedUsers # Default to current state if not set, for backward compatibility pre v8.6.0
7171

72-
$StateIsCorrect = ($CurrentState.AllowAnonymousUsersToJoinMeeting -eq $Settings.AllowAnonymousUsersToJoinMeeting) -and
73-
($CurrentState.AllowAnonymousUsersToStartMeeting -eq $Settings.AllowAnonymousUsersToStartMeeting) -and
72+
# Untoggled switches are absent from the settings; default them to $false (the CIS recommended value) so we never send null to the ConfigApi
73+
$AllowAnonymousUsersToJoinMeeting = $Settings.AllowAnonymousUsersToJoinMeeting ?? $false
74+
$AllowAnonymousUsersToStartMeeting = $Settings.AllowAnonymousUsersToStartMeeting ?? $false
75+
$AllowPSTNUsersToBypassLobby = $Settings.AllowPSTNUsersToBypassLobby ?? $false
76+
$AllowExternalParticipantGiveRequestControl = $Settings.AllowExternalParticipantGiveRequestControl ?? $false
77+
$AllowParticipantGiveRequestControl = $Settings.AllowParticipantGiveRequestControl ?? $false
78+
79+
$StateIsCorrect = ($CurrentState.AllowAnonymousUsersToJoinMeeting -eq $AllowAnonymousUsersToJoinMeeting) -and
80+
($CurrentState.AllowAnonymousUsersToStartMeeting -eq $AllowAnonymousUsersToStartMeeting) -and
7481
($CurrentState.AutoAdmittedUsers -eq $AutoAdmittedUsers) -and
75-
($CurrentState.AllowPSTNUsersToBypassLobby -eq $Settings.AllowPSTNUsersToBypassLobby) -and
82+
($CurrentState.AllowPSTNUsersToBypassLobby -eq $AllowPSTNUsersToBypassLobby) -and
7683
($CurrentState.MeetingChatEnabledType -eq $MeetingChatEnabledType) -and
7784
($CurrentState.DesignatedPresenterRoleMode -eq $DesignatedPresenterRoleMode) -and
78-
($CurrentState.AllowExternalParticipantGiveRequestControl -eq $Settings.AllowExternalParticipantGiveRequestControl) -and
79-
($CurrentState.AllowParticipantGiveRequestControl -eq $Settings.AllowParticipantGiveRequestControl)
85+
($CurrentState.AllowExternalParticipantGiveRequestControl -eq $AllowExternalParticipantGiveRequestControl) -and
86+
($CurrentState.AllowParticipantGiveRequestControl -eq $AllowParticipantGiveRequestControl)
8087

8188

8289
if ($Settings.remediate -eq $true) {
@@ -85,14 +92,14 @@ function Invoke-CIPPStandardTeamsGlobalMeetingPolicy {
8592
} else {
8693
$cmdParams = @{
8794
Identity = 'Global'
88-
AllowAnonymousUsersToJoinMeeting = $Settings.AllowAnonymousUsersToJoinMeeting
89-
AllowAnonymousUsersToStartMeeting = $Settings.AllowAnonymousUsersToStartMeeting
95+
AllowAnonymousUsersToJoinMeeting = $AllowAnonymousUsersToJoinMeeting
96+
AllowAnonymousUsersToStartMeeting = $AllowAnonymousUsersToStartMeeting
9097
AutoAdmittedUsers = $AutoAdmittedUsers
91-
AllowPSTNUsersToBypassLobby = $Settings.AllowPSTNUsersToBypassLobby
98+
AllowPSTNUsersToBypassLobby = $AllowPSTNUsersToBypassLobby
9299
MeetingChatEnabledType = $MeetingChatEnabledType
93100
DesignatedPresenterRoleMode = $DesignatedPresenterRoleMode
94-
AllowExternalParticipantGiveRequestControl = $Settings.AllowExternalParticipantGiveRequestControl
95-
AllowParticipantGiveRequestControl = $Settings.AllowParticipantGiveRequestControl
101+
AllowExternalParticipantGiveRequestControl = $AllowExternalParticipantGiveRequestControl
102+
AllowParticipantGiveRequestControl = $AllowParticipantGiveRequestControl
96103
}
97104

98105
try {
@@ -127,14 +134,14 @@ function Invoke-CIPPStandardTeamsGlobalMeetingPolicy {
127134
AllowParticipantGiveRequestControl = $CurrentState.AllowParticipantGiveRequestControl
128135
}
129136
$ExpectedValue = @{
130-
AllowAnonymousUsersToJoinMeeting = $Settings.AllowAnonymousUsersToJoinMeeting
131-
AllowAnonymousUsersToStartMeeting = $Settings.AllowAnonymousUsersToStartMeeting
137+
AllowAnonymousUsersToJoinMeeting = $AllowAnonymousUsersToJoinMeeting
138+
AllowAnonymousUsersToStartMeeting = $AllowAnonymousUsersToStartMeeting
132139
AutoAdmittedUsers = $AutoAdmittedUsers
133-
AllowPSTNUsersToBypassLobby = $Settings.AllowPSTNUsersToBypassLobby
140+
AllowPSTNUsersToBypassLobby = $AllowPSTNUsersToBypassLobby
134141
MeetingChatEnabledType = $MeetingChatEnabledType
135142
DesignatedPresenterRoleMode = $DesignatedPresenterRoleMode
136-
AllowExternalParticipantGiveRequestControl = $Settings.AllowExternalParticipantGiveRequestControl
137-
AllowParticipantGiveRequestControl = $Settings.AllowParticipantGiveRequestControl
143+
AllowExternalParticipantGiveRequestControl = $AllowExternalParticipantGiveRequestControl
144+
AllowParticipantGiveRequestControl = $AllowParticipantGiveRequestControl
138145
}
139146
Set-CIPPStandardsCompareField -FieldName 'standards.TeamsGlobalMeetingPolicy' -CurrentValue $CurrentValue -ExpectedValue $ExpectedValue -Tenant $Tenant
140147
Add-CIPPBPAField -FieldName 'TeamsGlobalMeetingPolicy' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $Tenant

0 commit comments

Comments
 (0)