Azure Custom PowerShell Script – Enable Azure Monitor for VM Insights

Sometimes there are lots of VM in your subscriptions, it needs take long time to enable VM Insights in the Azure Portal.

You can view this blog to see how to get use of PowerShell script to enable all the VM with VM Insights to save your time.

  1. Prerequisites
    1. Networking Connectivity

Please ensure customer network allowing below internet outbound from the VM.

  • *.ods.opinsights.azure.com
  • *.oms.opinsights.azure.com
  • *.blob.core.windows.net
  • *.azure-automation.net
    1. Log Analytics Workspace

Please create at least one log analytics workspace for log storing.

  1. PowerShell Module

Please ensure your PowerShell have installed the latest module with Enable-AzureRM feature.

You may reference from here.

https://docs.microsoft.com/en-us/azure/azure-monitor/vm/vminsights-enable-powershell#prerequisites

  1. PowerShell Script

Please save the attached PowerShell script to your computer.

  • Install-VMInsights
  • Install-VMInsights-parameter
  1. Open the Install-VMInsights-parameter.
    1. Set the path that you save the Install-VMInsights.ps1
    2. Set the parameter.
      • Tenant ID
      • Subscription ID
      • Workspace ID
      • Workspace Key
      • Workspace Region
      • Resource Group Name (Optional)

*If you set the resource group name, the scope will be that specific resource group, rather than subscription.

  • Open PowerShell as an administrator.
    • Copy and run the script.
    • It will list out all VM in the scope and require your confirmation.
  • Press Y to confirm and it will start the installation.
  • If there are any failed installation, it may cause by network connectivity or the OS compatibility. Please double check and confirm.
  1. VM Insight Agent upgrade

After the installation, we need to access the Azure portal and upgrade the agent.

  1. Go to Azure portal and open monitor
    1. Click Virtual Machine.
  • You are able to see the VM insight agent status from here.
  • If you confirm the machine are show as monitored, please select all and click Upgrade selected.

4. It will show a list to you.

  • Click Upgrade to continue.
  • When all process finishes, you may able to see the Monitor Coverage is Enabled and Guest VM Health is Healthy.
  • Reference

https://docs.microsoft.com/en-us/azure/azure-monitor/vm/vminsights-enable-powershell

https://docs.microsoft.com/en-us/azure/azure-monitor/vm/vminsights-enable-portal

You can visit our SOS GitHub for downloading the source code as a template:

https://github.com/SOSHKMVP/Azure-Monitor/tree/main/Enable%20Az%20monitor%20-%20VM%20Insight

Eric Chan
| + posts

Microsoft MVP
SOS Group Limited

Leave a comment

SOS Group Limited © 2024. All Rights Reserved.