Facebook
From Burly Human, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 172
  1. $myResourceGroup = "..."
  2. $myScaleSet = "..."
  3. $myLocation = "West Europe"
  4.  
  5.  
  6. # Define the script for your Custom Script Extension to run
  7. $customConfig = @{
  8.     "fileUris" = (,"https://raw.githubusercontent.com/iainfoulds/azure-samples/master/automate-iis.ps1");
  9.     "commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File automate-iis.ps1"
  10. }
  11.  
  12. # Get information about the scale set
  13. $vmss = Get-AzureRmVmss `
  14.                 -ResourceGroupName $myResourceGroup `
  15.                 -VMScaleSetName $myScaleSet -Verbose
  16.  
  17. $vmss.Zones.IsSynchronized
  18.  
  19. # Add the Custom Script Extension to install IIS and configure basic website
  20. $vmss = Add-AzureRmVmssExtension `
  21.     -VirtualMachineScaleSet $vmss `
  22.     -Name "customScript" `
  23.     -Publisher "Microsoft.Compute" `
  24.     -Type "CustomScriptExtension" `
  25.     -TypeHandlerVersion 1.8 `
  26.     -Setting $customConfig
  27.  
  28. # Update the scale set and apply the Custom Script Extension to the VM instances
  29. Update-AzureRmVmss `
  30.     -VMScaleSetName $myScaleSet `
  31.     -ResourceGroupName $myResourceGroup `
  32.     -VirtualMachineScaleSet $vmss -Verbose
  33.  
  34. # Update instances
  35. Update-AzureRmVmssInstance -ResourceGroupName $myResourceGroup -VMScaleSetName $myScaleSet -InstanceId "0"
  36.  
  37. # Scale out
  38. $myRuleScaleOut = New-AzureRmAutoscaleRule `
  39.     -MetricName "Percentage CPU" `
  40.     -MetricResourceId /subscriptions/$mySubscriptionId/resourceGroups/$myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/$myScaleSet `
  41.     -TimeGrain 00:01:00 `
  42.     -MetricStatistic Average `
  43.     -TimeWindow 00:07:00 `
  44.     -Operator GreaterThan `
  45.     -Threshold 50 `
  46.     -ScaleActionCooldown 00:05:00
  47.     -ScaleActionDirection Increase `
  48.     -ScaleActionScaleType ChangeCount `
  49.     -ScaleActionValue 1
  50.  
  51. # Scale in
  52. $myRuleScaleIn = New-AzureRmAutoscaleRule `
  53.     -MetricName "Percentage CPU" `
  54.     -MetricResourceId /subscriptions/$mySubscriptionId/resourceGroups/$myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/$myScaleSet `
  55.     -Operator LessThan `
  56.     -MetricStatistic Average `
  57.     -Threshold 20 `
  58.     -TimeGrain 00:01:00 `
  59.     -TimeWindow 00:07:00 `
  60.     -ScaleActionCooldown 00:05:00 `
  61.     -ScaleActionDirection Decrease `
  62.     -ScaleActionScaleType ChangeCount `
  63.     -ScaleActionValue 1
  64.  
  65. # Define an autoscale profile
  66. $myScaleProfile = New-AzureRmAutoscaleProfile `
  67.     -DefaultCapacity 1 `
  68.     -MaximumCapacity 3 `
  69.     -MinimumCapacity 1 `
  70.     -Rules $myRuleScaleOut,$myRuleScaleIn `
  71.     -Name "autoprofile"
  72.  
  73. # New powershell rule not rules
  74. $myScaleProfile = New-AzureRmAutoscaleProfile `
  75.     -DefaultCapacity 1 `
  76.     -MaximumCapacity 3 `
  77.     -MinimumCapacity 1 `
  78.     -Rule $myRuleScaleOut,$myRuleScaleIn `
  79.     -Name "autoprofile"
  80.  
  81. # Apply autoscale rules to a scale set
  82. Add-AzureRmAutoscaleSetting `
  83.   -Location $myLocation `
  84.   -Name "autosetting" `
  85.   -ResourceGroup $myResourceGroup `
  86.   -TargetResourceId /subscriptions/$mySubscriptionId/resourceGroups/$myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/$myScaleSet `
  87.   -AutoscaleProfiles $myScaleProfile
  88.  
  89. # New powershell AutoscaleProfiles not AutoscaleProfiles
  90.   Add-AzureRmAutoscaleSetting `
  91.   -Location $myLocation `
  92.   -Name "autosetting" `
  93.   -ResourceGroup $myResourceGroup `
  94.   -TargetResourceId /subscriptions/$mySubscriptionId/resourceGroups/$myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/$myScaleSet `
  95.   -AutoscaleProfiles $myScaleProfile