Open In App

How to Install OMS Agent for a Linux Virtual Machine using PowerShell?

Last Updated : 30 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Pre-requisite:- Azure

Here in this article, we will show how to add or install OMS Agent on a Linux Virtual Machine in Azure using PowerShell. Before diving into the process let’s know about what an OMS agent is. OMS Stands for Operations Management Suite Agent can be configured to collect the performance logs or the application logs of a Linux family Azure Virtual Machine by connecting it to Azure Log Analytics Workspace.

Steps to Configure OMS Agent on a Linux VM

Step 1: Log in to Azure Portal.

Step 2: Access the Azure Cloud Shell and Switch to PowerShell Terminal.

Step 3: Now Create a new file named installOMSAgent.ps1 using the touch command.

touch installOMSAgent.ps1

Step 4: Use the below-following command to write the code in a file.

code installOMSAgent.ps1
powershell

 

Step 5: Paste the below-following code in the install OMSAgent.ps1 file

$subName = "<default subscription name>"
Select-AzSubscription -Subscription $subName

$workspaceRG = "<resource group name>"
$workspace = Get-AzOperationalInsightsWorkspace -ResourceGroupName $workspaceRG
$workspaceId = $workspace.CustomerId
$workspaceKey = Get-AzOperationalInsightsWorkspaceSharedKeys -ResourceGroupName $workspaceRG -Name $Workspace.Name
$Publicsettings=@{"workspaceId" = $workspaceId}
$Protectedsettings=@{"workspaceKey" = $workspaceKey.primarysharedkey}

Set-AzVMExtension `
  -ResourceGroupName "<add VM resource group>" `
  -VMName "<add server name>" `
  -ExtensionName "OmsAgentForLinux" `
  -ExtensionType "OmsAgentForLinux" `
  -Publisher Microsoft.EnterpriseCloud.Monitoring `
  -TypeHandlerVersion latestVersion `
  -SettingString $PublicSettings `
  -ProtectedSettingString $ProtectedSettings `
  -Location "<location name>" `
  -EnableAutomaticUpgrade $true
code

 

Step 6: Save the file and run the code. Use the following command to run the code.

./installOMSAgent.ps1
powershell

 

Step 7: Go to your target Azure VM and check the Extensions + applications. You should see this “OmsAgentForLinux” extension on Azure VM if successful.

azure vm

 

This is how you can install an Operations Management Suite (OMS) extension for a Linux Virtual Machine in Microsoft Azure.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads