How to list all AZ VM local admin users

Oscar 177 Reputation points
2023-04-07T08:35:47.64+00:00

Hello, Is there a way to run Azure CLI and give commands on Azure VM like: give all local administrator users? For example, if we don't have access to Azure VM, but we do have Owner access to the Resource group or to Subscription.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,017 questions
{count} votes

Accepted answer
  1. TP 124.9K Reputation points Volunteer Moderator
    2023-04-07T09:01:16.2566667+00:00

    Hi,

    You can use sample code below to get list of members of local Administrators group on windows VM. Please note it takes some time for the extension to run the command on the VM and return the results, so be patient.

    az vm run-command invoke -g MyResourceGroup -n MyVM --command-id RunPowerShellScript --scripts "Get-LocalGroupMember -Group 'Administrators'"
    

    Thanks.

    -TP


1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.