Skip to content

Commit 2e320e3

Browse files
committed
Update Invoke-ExecTimeSettings.ps1
1 parent 5e80d13 commit 2e320e3

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecTimeSettings.ps1

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,18 @@ function Invoke-ExecTimeSettings {
5252

5353
Write-Information "Updating function app time settings: Timezone=$Timezone, BusinessHoursStart=$BusinessHoursStart, BusinessHoursEnd=$BusinessHoursEnd"
5454

55-
# Get current app settings
56-
$Token = Get-AzAccessToken -ResourceUrl 'https://management.azure.com'
57-
$Headers = @{
58-
Authorization = "Bearer $($Token.Token)"
59-
'Content-Type' = 'application/json'
55+
# Build app settings hashtable
56+
$AppSettings = @{
57+
'WEBSITE_TIME_ZONE' = $Timezone
6058
}
6159

62-
$AppSettingsUrl = "https://management.azure.com/subscriptions/$Subscription/resourceGroups/$RGName/providers/Microsoft.Web/sites/$FunctionName/config/appsettings/list?api-version=2022-03-01"
63-
64-
$CurrentSettings = Invoke-RestMethod -Uri $AppSettingsUrl -Method POST -Headers $Headers
65-
66-
# Update settings
67-
$CurrentSettings.properties['WEBSITE_TIME_ZONE'] = $Timezone
68-
6960
if ($env:WEBSITE_SKU -eq 'FlexConsumption') {
70-
$CurrentSettings.properties['CIPP_BUSINESS_HOURS_START'] = $BusinessHoursStart
71-
$CurrentSettings.properties['CIPP_BUSINESS_HOURS_END'] = $BusinessHoursEnd
61+
$AppSettings['CIPP_BUSINESS_HOURS_START'] = $BusinessHoursStart
62+
$AppSettings['CIPP_BUSINESS_HOURS_END'] = $BusinessHoursEnd
7263
}
7364

74-
# Save settings
75-
$UpdateUrl = "https://management.azure.com/subscriptions/$Subscription/resourceGroups/$RGName/providers/Microsoft.Web/sites/$FunctionName/config/appsettings?api-version=2022-03-01"
76-
77-
$UpdateResponse = Invoke-RestMethod -Uri $UpdateUrl -Method PUT -Headers $Headers -Body ($CurrentSettings | ConvertTo-Json -Depth 10)
65+
# Update app settings using native cmdlet (managed identity authentication handled automatically)
66+
Update-AzFunctionAppSetting -Name $FunctionName -ResourceGroupName $RGName -AppSetting $AppSettings -ErrorAction Stop | Out-Null
7867

7968
Write-LogMessage -API 'ExecTimeSettings' -headers $Request.Headers -message "Updated time settings: Timezone=$Timezone, BusinessHours=$BusinessHoursStart-$BusinessHoursEnd" -Sev 'Info'
8069

0 commit comments

Comments
 (0)