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