Hello @Vaishnav AV-FT !
I have seen that the commands are not accepted .
Theres is a whole new approach
For the meantime have a look please :
# Generates a Random Value
$Random=(New-Guid).ToString().Substring(0,8)
# Variables
$ResourceGroupName="myResourceGroup$random"
$AppName="AppServiceManualScale$random"
$Location="WestUS"
# Create a Resource Group
New-AzResourceGroup -Name $ResourceGroupName -Location $Location
# Create an App Service Plan
New-AzAppservicePlan -Name AppServiceManualScalePlan -ResourceGroupName $ResourceGroupName -Location $Location -Tier Basic
# Create a Web App in the App Service Plan
New-AzWebApp -Name $AppName -ResourceGroupName $ResourceGroupName -Location $Location -AppServicePlan AppServiceManualScalePlan
# Scale Web App to 2 Workers
Set-AzAppServicePlan -NumberofWorkers 2 -Name AppServiceManualScalePlan -ResourceGroupName $ResourceGroupName
https://learn.microsoft.com/en-us/azure/app-service/scripts/powershell-scale-manual
I am also looking into different scenarios and got here :
https://learn.microsoft.com/en-us/azure/azure-monitor/autoscale/autoscale-multiprofile?tabs=powershell
owerShell can be used to create multiple profiles in your autoscale settings.
See the PowerShell Az.Monitor Reference for the full set of autoscale PowerShell commands.
The following steps show how to create an autoscale profile using PowerShell.
Create rules using New-AzAutoscaleRule.
Create profiles using New-AzAutoscaleProfile using the rules from the previous step.
Use Add-AzAutoscaleSetting to apply the profiles to your autoscale setting.
Add a recurring profile using PowerShell
The example below shows how to create default profile and a recurring autoscale profile, recurring on Wednesdays and Fridays between 09:00 and 23:00. The default profile uses the CpuIn and CpuOut Rules. The recurring profile uses the BandwidthIn and BandwidthOut rules.
Azure PowerShell
Copy
$ResourceGroupName="rg-vmss-001"
$TargetResourceId="/subscriptions/abc123456-987-f6e5-d43c-9a8d8e7f6541/resourceGroups/rg-vmss-001/providers/Microsoft.Compute/virtualMachineScaleSets/vmss-001"
$ScaleSettingName="vmss-autoscalesetting=001"
$CpuOut=New-AzAutoscaleScaleRuleObject `
-MetricTriggerMetricName "Percentage CPU" `
-MetricTriggerMetricResourceUri "$TargetResourceId" `
-MetricTriggerTimeGrain ([System.TimeSpan]::New(0,1,0)) `
-MetricTriggerStatistic "Average" `
-MetricTriggerTimeWindow ([System.TimeSpan]::New(0,5,0)) `
-MetricTriggerTimeAggregation "Average" `
-MetricTriggerOperator "GreaterThan" `
-MetricTriggerThreshold 50 `
-MetricTriggerDividePerInstance $false `
-ScaleActionDirection "Increase" `
-ScaleActionType "ChangeCount" `
-ScaleActionValue 1 `
-ScaleActionCooldown ([System.TimeSpan]::New(0,5,0))
$CpuIn=New-AzAutoscaleScaleRuleObject `
-MetricTriggerMetricName "Percentage CPU" `
-MetricTriggerMetricResourceUri "$TargetResourceId" `
-MetricTriggerTimeGrain ([System.TimeSpan]::New(0,1,0)) `
-MetricTriggerStatistic "Average" `
-MetricTriggerTimeWindow ([System.TimeSpan]::New(0,5,0)) `
-MetricTriggerTimeAggregation "Average" `
-MetricTriggerOperator "LessThan" `
-MetricTriggerThreshold 30 `
-MetricTriggerDividePerInstance $false `
-ScaleActionDirection "Decrease" `
-ScaleActionType "ChangeCount" `
-ScaleActionValue 1 `
-ScaleActionCooldown ([System.TimeSpan]::New(0,5,0))
$defaultProfile=New-AzAutoscaleProfileObject `
-Name "Default" `
-CapacityDefault 1 `
-CapacityMaximum 5 `
-CapacityMinimum 1 `
-Rule $CpuOut, $CpuIn
$BandwidthIn=New-AzAutoscaleScaleRuleObject `
-MetricTriggerMetricName "VM Cached Bandwidth Consumed Percentage" `
-MetricTriggerMetricResourceUri "$TargetResourceId" `
-MetricTriggerTimeGrain ([System.TimeSpan]::New(0,1,0)) `
-MetricTriggerStatistic "Average" `
-MetricTriggerTimeWindow ([System.TimeSpan]::New(0,5,0)) `
-MetricTriggerTimeAggregation "Average" `
-MetricTriggerOperator "LessThan" `
-MetricTriggerThreshold 30 `
-MetricTriggerDividePerInstance $false `
-ScaleActionDirection "Decrease" `
-ScaleActionType "ChangeCount" `
-ScaleActionValue 1 `
-ScaleActionCooldown ([System.TimeSpan]::New(0,5,0))
$BandwidthOut=New-AzAutoscaleScaleRuleObject `
-MetricTriggerMetricName "VM Cached Bandwidth Consumed Percentage" `
-MetricTriggerMetricResourceUri "$TargetResourceId" `
-MetricTriggerTimeGrain ([System.TimeSpan]::New(0,1,0)) `
-MetricTriggerStatistic "Average" `
-MetricTriggerTimeWindow ([System.TimeSpan]::New(0,5,0)) `
-MetricTriggerTimeAggregation "Average" `
-MetricTriggerOperator "GreaterThan" `
-MetricTriggerThreshold 60 `
-MetricTriggerDividePerInstance $false `
-ScaleActionDirection "Increase" `
-ScaleActionType "ChangeCount" `
-ScaleActionValue 1 `
-ScaleActionCooldown ([System.TimeSpan]::New(0,5,0))
$RecurringProfile=New-AzAutoscaleProfileObject `
-Name "Wednesdays and Fridays" `
-CapacityDefault 1 `
-CapacityMaximum 10 `
-CapacityMinimum 1 `
-RecurrenceFrequency week `
-ScheduleDay "Wednesday","Friday" `
-ScheduleHour 09 `
-ScheduleMinute 00 `
-ScheduleTimeZone "Pacific Standard Time" `
-Rule $BandwidthIn, $BandwidthOut
$DefaultProfile2=New-AzAutoscaleProfileObject `
-Name "Back to default after Wednesday and Friday" `
-CapacityDefault 1 `
-CapacityMaximum 5 `
-CapacityMinimum 1 `
-RecurrenceFrequency week `
-ScheduleDay "Wednesday","Friday" `
-ScheduleHour 23 `
-ScheduleMinute 00 `
-ScheduleTimeZone "Pacific Standard Time" `
-Rule $CpuOut, $CpuIn
Update-AzAutoscaleSetting `
-name $ScaleSettingName `
-ResourceGroup $ResourceGroupName `
-Enabled $true `
-TargetResourceUri $TargetResourceId `
-Profile $DefaultProfile, $RecurringProfile, $DefaultProfile2
Note
You can't specify an end date for recurring profiles in PowerShell. To end a recurring profile, create a copy of default profile with the same recurrence parameters as the recurring profile. Set the start time to be the time you want the recurring profile to end. Each recurring profile requires its own copy of the default profile to specify an end time.
Updating the default profile when you have recurring profiles
If you have multiple recurring profiles and want to change your default profile, the change must be made to each default profile corresponding to a recurring profile.
For example, if you have two recurring profiles called SundayProfile and ThursdayProfile, you need two New-AzAutoscaleProfile commands to change to the default profile.
Azure PowerShell
Copy
$DefaultProfileSundayProfile = New-AzAutoscaleProfile -DefaultCapacity "1" -MaximumCapacity "10" -MinimumCapacity "1" -Rule $CpuOut,$CpuIn -Name "Defalut for Sunday" -RecurrenceFrequency week -ScheduleDay "Sunday" -ScheduleHour 19 -ScheduleMinute 00 -ScheduleTimeZone "Pacific Standard Time"`
$DefaultProfileThursdayProfile = New-AzAutoscaleProfile -DefaultCapacity "1" -MaximumCapacity "10" -MinimumCapacity "1" -Rule $CpuOut,$CpuIn -Name "Default for Thursday" -RecurrenceFrequency week -ScheduleDay "Thursday" -ScheduleHour 19 -ScheduleMinute 00 -ScheduleTimeZone "Pacific Standard Time"`
I hope this helps!
Kindly mark the answer as Accepted and Upvote in case it helped!
Regards