- $myResourceGroup = "..."
- $myScaleSet = "..."
- $myLocation = "West Europe"
- # Define the script for your Custom Script Extension to run
- $customConfig = @{
- "fileUris" = (,"https://raw.githubusercontent.com/iainfoulds/azure-samples/master/automate-iis.ps1");
- "commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File automate-iis.ps1"
- }
- # Get information about the scale set
- $vmss = Get-AzureRmVmss `
- -ResourceGroupName $myResourceGroup `
- -VMScaleSetName $myScaleSet -Verbose
- $vmss.Zones.IsSynchronized
- # Add the Custom Script Extension to install IIS and configure basic website
- $vmss = Add-AzureRmVmssExtension `
- -VirtualMachineScaleSet $vmss `
- -Name "customScript" `
- -Publisher "Microsoft.Compute" `
- -Type "CustomScriptExtension" `
- -TypeHandlerVersion 1.8 `
- -Setting $customConfig
- # Update the scale set and apply the Custom Script Extension to the VM instances
- Update-AzureRmVmss `
- -VMScaleSetName $myScaleSet `
- -ResourceGroupName $myResourceGroup `
- -VirtualMachineScaleSet $vmss -Verbose
- # Update instances
- Update-AzureRmVmssInstance -ResourceGroupName $myResourceGroup -VMScaleSetName $myScaleSet -InstanceId "0"
- # Scale out
- $myRuleScaleOut = New-AzureRmAutoscaleRule `
- -MetricName "Percentage CPU" `
- -MetricResourceId /subscriptions/$mySubscriptionId/resourceGroups/$myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/$myScaleSet `
- -TimeGrain 00:01:00 `
- -MetricStatistic Average `
- -TimeWindow 00:07:00 `
- -Operator GreaterThan `
- -Threshold 50 `
- -ScaleActionCooldown 00:05:00
- -ScaleActionDirection Increase `
- -ScaleActionScaleType ChangeCount `
- -ScaleActionValue 1
- # Scale in
- $myRuleScaleIn = New-AzureRmAutoscaleRule `
- -MetricName "Percentage CPU" `
- -MetricResourceId /subscriptions/$mySubscriptionId/resourceGroups/$myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/$myScaleSet `
- -Operator LessThan `
- -MetricStatistic Average `
- -Threshold 20 `
- -TimeGrain 00:01:00 `
- -TimeWindow 00:07:00 `
- -ScaleActionCooldown 00:05:00 `
- -ScaleActionDirection Decrease `
- -ScaleActionScaleType ChangeCount `
- -ScaleActionValue 1
- # Define an autoscale profile
- $myScaleProfile = New-AzureRmAutoscaleProfile `
- -DefaultCapacity 1 `
- -MaximumCapacity 3 `
- -MinimumCapacity 1 `
- -Rules $myRuleScaleOut,$myRuleScaleIn `
- -Name "autoprofile"
- # New powershell rule not rules
- $myScaleProfile = New-AzureRmAutoscaleProfile `
- -DefaultCapacity 1 `
- -MaximumCapacity 3 `
- -MinimumCapacity 1 `
- -Rule $myRuleScaleOut,$myRuleScaleIn `
- -Name "autoprofile"
- # Apply autoscale rules to a scale set
- Add-AzureRmAutoscaleSetting `
- -Location $myLocation `
- -Name "autosetting" `
- -ResourceGroup $myResourceGroup `
- -TargetResourceId /subscriptions/$mySubscriptionId/resourceGroups/$myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/$myScaleSet `
- -AutoscaleProfiles $myScaleProfile
- # New powershell AutoscaleProfiles not AutoscaleProfiles
- Add-AzureRmAutoscaleSetting `
- -Location $myLocation `
- -Name "autosetting" `
- -ResourceGroup $myResourceGroup `
- -TargetResourceId /subscriptions/$mySubscriptionId/resourceGroups/$myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/$myScaleSet `
- -AutoscaleProfiles $myScaleProfile