Skip to content

Commit fff3c60

Browse files
committed
Standardize tenant variable usage in CA policy script
Replaced inconsistent usage of $tenant and $Tenant variables with $TenantFilter in Write-LogMessage and New-GraphPostRequest calls to ensure correct tenant context throughout New-CIPPCAPolicy.ps1.
1 parent 34b564c commit fff3c60

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Modules/CIPPCore/Public/New-CIPPCAPolicy.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function New-CIPPCAPolicy {
153153
name = ($CheckExisting | Where-Object -Property displayName -EQ $Location.displayName).displayName
154154
templateId = $location.id
155155
}
156-
Write-LogMessage -Headers $User -API $APINAME -message "Matched a CA policy with the existing Named Location: $($location.displayName)" -Sev 'Info'
156+
Write-LogMessage -Tenant $TenantFilter -Headers $User -API $APINAME -message "Matched a CA policy with the existing Named Location: $($location.displayName)" -Sev 'Info'
157157

158158
} else {
159159
if ($location.countriesAndRegions) { $location.countriesAndRegions = @($location.countriesAndRegions) }
@@ -169,7 +169,7 @@ function New-CIPPCAPolicy {
169169
Start-Sleep -Seconds 2
170170
$retryCount++
171171
} while ((!$LocationRequest -or !$LocationRequest.id) -and ($retryCount -lt 5))
172-
Write-LogMessage -Headers $User -API $APINAME -message "Created new Named Location: $($location.displayName)" -Sev 'Info'
172+
Write-LogMessage -Tenant $TenantFilter -Headers $User -API $APINAME -message "Created new Named Location: $($location.displayName)" -Sev 'Info'
173173
[pscustomobject]@{
174174
id = $GraphRequest.id
175175
name = $GraphRequest.displayName
@@ -248,7 +248,7 @@ function New-CIPPCAPolicy {
248248
}
249249
} catch {
250250
$ErrorMessage = Get-CippException -Exception $_
251-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to replace displayNames for conditional access rule $($JSONobj.displayName). Error: $($ErrorMessage.NormalizedError)" -sev 'Error' -LogData $ErrorMessage
251+
Write-LogMessage -API 'Standards' -tenant $TenantFilter -message "Failed to replace displayNames for conditional access rule $($JSONobj.displayName). Error: $($ErrorMessage.NormalizedError)" -sev 'Error' -LogData $ErrorMessage
252252
throw "Failed to replace displayNames for conditional access rule $($JSONobj.displayName): $($ErrorMessage.NormalizedError)"
253253
}
254254
}
@@ -278,8 +278,8 @@ function New-CIPPCAPolicy {
278278
#Send request to disable security defaults.
279279
$body = '{ "isEnabled": false }'
280280
try {
281-
$null = New-GraphPostRequest -tenantid $tenant -Uri 'https://graph.microsoft.com/beta/policies/identitySecurityDefaultsEnforcementPolicy' -Type patch -Body $body -asApp $true -ContentType 'application/json'
282-
Write-LogMessage -Headers $User -API 'Create CA Policy' -tenant $($Tenant) -message "Disabled Security Defaults for tenant $($TenantFilter)" -Sev 'Info'
281+
$null = New-GraphPostRequest -tenantid $TenantFilter -Uri 'https://graph.microsoft.com/beta/policies/identitySecurityDefaultsEnforcementPolicy' -Type patch -Body $body -asApp $true -ContentType 'application/json'
282+
Write-LogMessage -Headers $User -API 'Create CA Policy' -tenant $TenantFilter -message "Disabled Security Defaults for tenant $($TenantFilter)" -Sev 'Info'
283283
Start-Sleep 3
284284
} catch {
285285
$ErrorMessage = Get-CippException -Exception $_
@@ -340,7 +340,7 @@ function New-CIPPCAPolicy {
340340
}
341341
} catch {
342342
$ErrorMessage = Get-CippException -Exception $_
343-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to create or update conditional access rule $($JSONobj.displayName): $($ErrorMessage.NormalizedError) " -sev 'Error' -LogData $ErrorMessage
343+
Write-LogMessage -API 'Standards' -tenant $TenantFilter -message "Failed to create or update conditional access rule $($JSONobj.displayName): $($ErrorMessage.NormalizedError) " -sev 'Error' -LogData $ErrorMessage
344344

345345
Write-Warning "Failed to create or update conditional access rule $($JSONobj.displayName): $($ErrorMessage.NormalizedError)"
346346
Write-Information $_.InvocationInfo.PositionMessage

0 commit comments

Comments
 (0)