Member-only story
How to update a VM to Send to Log Analytics after Provisioning on Azure
Azure Powershell Gallery | Azure Modules | Azure VM | Log Analytics
There may be a need to quickly update a current Virtual Machine to utilize Log Analytics. This may be needed when declarative approaches do not work after provisioning. For example, setting up an ARM template with a VM and then updating it. This might be because the OSDisk (Operating System Disk) within the VM does not contain the agents and cannot be added. No worries this can be quickly done.
Pre-Requisites
- Assumes that you already have a Log Analytics with a Workspace ID and Workspace Key.
Step 1. Install the Az.Compute Module
This is required as the PowerShell script utilizes the Set-AzVMExtention. So run the following:
Install-Module -Name Az.Compute
Step 2. Create a Powershell script
Create a file called βenable-log-analytics.ps1β. Add the following:
$PublicSettings = @{"workspaceId" = "<your-workspace-id>"}
$ProtectedSettings = @{"workspaceKey" = "<your-workspace-key"}Set-AzVMExtension -ExtensionName "MicrosoftMonitoringAgent" `β¦