I am trying to disable MicrosoftMonitoringAgent on VM. I am using Automation account system assigned managed identity which has virtual machine contributor role. I am executing the below command using runbook.
Get-Service -Computer $vmName -Name $service
I am getting the error Cannot open Service Control Manager on computer 'xx'. This operation might require other privileges.
What permissions do I need or enable anything so the command works.
The error encountered is due to insufficient permissions on the
VM. To stop the services on the VM, you may requirelocal adminaccess.The
Virtual Machine Contributorrole does not have local admin access. To obtainlocal adminprivileges on a VM, you must assign both theVirtual Machine Administrator LoginforLocal adminandVirtual Machine Contributorrole forMicrosoft.Compute/virtualMachines/runCommand/writepermission, or alternatively, create a custom role with the required permissions.Output:
After executing the script, the AzureMonitorAgent service has been successfully disabled on the
Azure VM.Reference: Limiting access to Run Command
Virtual Machine Administrator Login