Showing posts with label VMSS Extensions. Show all posts
Showing posts with label VMSS Extensions. Show all posts

Wednesday, November 10, 2021

Add VMSS extensions with settings and protected settings- Powershell

 The below script guides you to add/remove a vmss extension in Azure. The example is for adding Microsoft Monitoring Agent to Azure vmss which will have workspace Id to collect custom logs from VM's


Get VMSS to a variable

$vmssname= Get-AzVmss -ResourceGroupName npqatx -VMScaleSetName <vmssname>

$workspaceId="GUID of log analytics workspace"

 $workspaceKey="workspace key"

$settings=@{"workspaceId" = $workspaceId}

$protSettings=@{"workspaceKey" = $workspaceKey}

#Adding new extension

Add-AzVmssExtension -VirtualMachineScaleSet $vmssname -Name "MMAExtension" -Publisher "Microsoft.EnterpriseCloud.Monitoring" -Type "MicrosoftMonitoringAgent" -TypeHandlerVersion "1.0" -AutoUpgradeMinorVersion $true -Setting $settings -ProtectedSetting $protSettings

Update-AzVmss -ResourceGroupName "RGName" -VMScaleSetName $vmssname.Name -VirtualMachineScaleSet $vmssname


#Remove existing vmss extension

Remove-AzVmssExtension -VirtualMachineScaleSet $webvmss -Name "MMAExtension"

Update-AzVmss -ResourceGroupName "RGName" -VMScaleSetName $vmssname.Name -VirtualMachineScaleSet $vmssname


#make sure to upgrade instances in vmss to the latest model after every change to vmss.

Sunday, October 17, 2021

Azure Monitoring Agent extension for VMSS- Updating through ARM template

 You can add multiple extensions to Azure VMSS  through the extensionProfile of ARM template. The below script shows the extension configuration and mapping workspaceId to collect custom logs from VMSS instances.


{
                "name""AxMAExtension",
                "properties": {
                  "autoUpgradeMinorVersion"true,
                  "protectedSettings": {
                    "workspaceKey""[listKeys(resourceId(parameters('RGName'),'Microsoft.OperationalInsights/workspaces/', parameters('workspacename')),'2015-11-01-preview').primarySharedKey]"
                  },
                  "publisher""Microsoft.Azure.Monitor",
                  "settings": {
                    "workspaceId""[reference(resourceId(parameters('RGName'),'Microsoft.OperationalInsights/workspaces/', parameters('workspacename')), '2015-11-01-preview').customerId]"
                  },
                  "type""AzureMonitorWindowsAgent",
                  "typeHandlerVersion""1.0"
                }
              }