Get-Service 命令给我错误无法在计算机“xx”上打开服务控制管理器。此操作可能需要其他权限

问题描述 投票:0回答:1

我正在尝试禁用虚拟机上的 MicrosoftMonitoringAgent。我正在使用自动化帐户系统分配的托管标识,该标识具有虚拟机贡献者角色。我正在使用 Runbook 执行以下命令。

Get-Service -Computer $vmName -Name $service

我收到错误 无法打开计算机“xx”上的服务控制管理器。此操作可能需要其他权限。

我需要什么权限或启用任何内容才能使命令正常工作。

azure powershell azure-automation azure-monitoring
1个回答
0
投票

Get-Service 命令给出错误无法在计算机“xx”上打开服务控制管理器。此操作可能需要其他权限。

遇到的错误是由于VM上的

权限不足
。要停止虚拟机上的服务,您可能需要
local admin
访问权限。

Virtual Machine Contributor
角色没有本地管理员访问权限。要获得
VM
上的 local admin 权限,您必须分配
Virtual Machine Administrator Login
Local admin
Virtual Machine Contributor
权限的
Microsoft.Compute/virtualMachines/runCommand/write
角色,或者创建具有所需权限的自定义角色。

 $scriptContent = @"
 Set-Service -name "AzureMonitorAgent" -startupType disabled
"@  
az vm run-command invoke --command-id RunPowerShellScript --name "Venkat-windows" -g 'Venkat' --scripts "$scriptContent"

输出:

enter image description here

执行脚本后,Azure VM上的

AzureMonitorAgent
服务已成功禁用。

enter image description here

参考:限制对运行命令的访问

虚拟机管理员登录

© www.soinside.com 2019 - 2024. All rights reserved.