0
votes

I have prepared simple powershell script for creating Log Analytics computer group. Based on that group I want to add VMs to the Update Management solution in Azure. Command presented below. For now I can add few VMs using this structure 'Heartbeat | where (Computer == "vmA" or Computer == "vmB")'. This approach is good for few VMs, question is what can I do with a list of 50 or more VMs? Is there any way to pass variable/param to this -Query?

 New-AzOperationalInsightsComputerGroup `
-ResourceGroupName "testRG" `
-WorkspaceName "Testloganalytics" `
-SavedSearchId "testID01" `
-DisplayName "GroupName" `
-Category "Updates" `
-Query 'Heartbeat | where (Computer == "vmA" or Computer  == "vmB")' `
-Version 1 `
-Force
1

1 Answers

1
votes

You can specify a variable which contains all the vms like this:

$myvms = '("vm1","vm2","vm3","vm4","vm5")'

then, for the -Query, you can use the in operator, the command like below:

-Query "Heartbeat | where Computer in $myvms"