You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Write-Warning"Multiple named locations found with display name '$($Location.displayName)'. Using the first match: $($ExistingLocation[0].id). IDs found: $($ExistingLocation.id-join', ')"
@@ -241,18 +243,21 @@ function New-CIPPCAPolicy {
241
243
} catch {
242
244
$ErrorMessage=Get-CippException-Exception $_
243
245
Write-Information"Error updating named location: $($ErrorMessage|ConvertTo-Json-Depth 10-Compress)"
244
-
Write-Warning"Failed to update location $($location.displayName): $($ErrorMessage.NormalizedError)"
245
-
Write-LogMessage-Tenant $TenantFilter-Headers $Headers-API $APIName-message "Failed to update existing Named Location: $($location.displayName). Error: $($ErrorMessage.NormalizedError)"-Sev 'Error'-LogData $ErrorMessage
246
+
Write-LogMessage-Tenant $TenantFilter-Headers $Headers-API $APIName-message "Named Location '$($location.displayName)' (id: $($ExistingLocation.id)) could not be updated — it may have been deleted. Will attempt to create it. Error: $($ErrorMessage.NormalizedError)"-Sev 'Warn'-LogData $ErrorMessage
247
+
$locationExistsInCache=$false
246
248
}
247
249
} else {
248
250
Write-LogMessage-Tenant $TenantFilter-Headers $Headers-API $APIName-message "Matched a CA policy with the existing Named Location: $($location.displayName)"-Sev 'Info'
249
251
}
250
-
[pscustomobject]@{
251
-
id=$ExistingLocation.id
252
-
name=$ExistingLocation.displayName
253
-
templateId=$location.id
252
+
if ($locationExistsInCache) {
253
+
[pscustomobject]@{
254
+
id=$ExistingLocation.id
255
+
name=$ExistingLocation.displayName
256
+
templateId=$location.id
257
+
}
254
258
}
255
-
} else {
259
+
}
260
+
if (-not$locationExistsInCache) {
256
261
if ($location.countriesAndRegions) { $location.countriesAndRegions=@($location.countriesAndRegions) }
257
262
$LocationBody=$location|Select-Object*-ExcludeProperty id
258
263
Remove-ODataProperties-Object $LocationBody
@@ -280,6 +285,7 @@ function New-CIPPCAPolicy {
280
285
if (!$LocationRequest-or!$LocationRequest.id) {
281
286
Write-Warning"Location created but could not verify availability after $MaxRetryCount attempts. Proceeding anyway."
282
287
}
288
+
$NewLocationsCreated=$true
283
289
Write-LogMessage-Tenant $TenantFilter-Headers $Headers-API $APIName-message "Created new Named Location: $($location.displayName)"-Sev 'Info'
284
290
} catch {
285
291
$ErrorMessage=Get-CippException-Exception $_
@@ -445,7 +451,7 @@ function New-CIPPCAPolicy {
445
451
# Preserve any exclusion groups named "Vacation Exclusion - <PolicyDisplayName>" from existing policy
0 commit comments