Add multiple Azure VMs to a log analytics workspace for monitoring

I wanted to add a bunch of VMs in a subscription to a log analytics workspace in Azure so I can add it to update management etc. Didn’t find any command when I Googled for this, so here’s a blog post in case anyone else searches for it.

There isn’t anything fancy in what I am doing. The way to do it for a single VM is in this official doc. I just loop around it for all VMs.

Get the workspace ID and key from Log Analytics workspace > [your workspace] > Overview > “1. Connect a data source” > “Windows, Linux, and other sources”