Forum Discussion
Connect OMS on multiple VMs
- Jan 24, 2018
Hi, Yes it is possible. The command will depend on the OS - Linux or windows but in general here is the code for Windows:
[string]$Settings ='{"workspaceId":"' + $OMSLogAnalyticsWorkspaceID + '"}'; [string]$ProtectedSettings ='{"workspaceKey":"' + $OMSLogAnalyticsPrimaryKey + '"}'; Set-AzureRmVMExtension ` -ResourceGroupName $ResourceGroupName ` -VMName $VMName ` -Name 'Microsoft.EnterpriseCloud.Monitoring' ` -Publisher 'Microsoft.EnterpriseCloud.Monitoring' ` -TypeHandlerVersion '1.0' ` -ExtensionType 'MicrosoftMonitoringAgent' ` -Location $Location ` -SettingString $Settings ` -ProtectedSettingString $ProtectedSettingsFor Linux is similar, only extension type is different OmsAgentForLinux and the name can be changed as well.
Hi, Yes it is possible. The command will depend on the OS - Linux or windows but in general here is the code for Windows:
[string]$Settings ='{"workspaceId":"' + $OMSLogAnalyticsWorkspaceID + '"}';
[string]$ProtectedSettings ='{"workspaceKey":"' + $OMSLogAnalyticsPrimaryKey + '"}';
Set-AzureRmVMExtension `
-ResourceGroupName $ResourceGroupName `
-VMName $VMName `
-Name 'Microsoft.EnterpriseCloud.Monitoring' `
-Publisher 'Microsoft.EnterpriseCloud.Monitoring' `
-TypeHandlerVersion '1.0' `
-ExtensionType 'MicrosoftMonitoringAgent' `
-Location $Location `
-SettingString $Settings `
-ProtectedSettingString $ProtectedSettings
For Linux is similar, only extension type is different OmsAgentForLinux and the name can be changed as well.
I think this script is only working for a single Resource Group that contains the 400 VMs.
what happens if we having all the VMs in different-different resource groups and regions.
what we do at that time how to move them all into the OMS.
- Aug 02, 2018
Hi Prashant,
I've only provided a snippet not a script. The snippet can be taken and you can implement whatever logic you want to walk trough every VM. The resource group, vm name and the location are all values that can be taken from the VM properties. Additionally now you can use Azure Policy to the agent installation was well.
Examples from Kristian Nese:
https://github.com/krnese/arm-sample/blob/master/mgmt/policies/mgmt/omsDeployIfNotExistsWindows.json
https://github.com/krnese/arm-sample/blob/master/mgmt/policies/mgmt/omsDeployIfNotExistsLinux.json