question

GlennMaxwell-2309 avatar image
0 Votes"
GlennMaxwell-2309 asked ManuPhilip commented

Azure VM status permissions

Hi All

i have a resource groups lets say resourcegroup1 it has Azure Virtual Desktops in it and my requirement is to know what is the status of the Virtual Machine(Azure virtual desktop VMs) in this resource group i.e it is running or stopped state and i want to fetch this using PowerShell. so i have created a custom role and provide the below access, using this permission i am not getting the status of the VM but i can get the VM name. experts guide me what permissions are required for VM status

Microsoft.Compute/virtualMachines/read

azure-virtual-machinesazure-virtual-desktopazure-rbac
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ManuPhilip avatar image
0 Votes"
ManuPhilip answered ManuPhilip commented

I found a way to get the VM status as follows: Check, if this helps !

Find WvdSessionHost Name as below:

 Get-AzWvdSessionHost "ResourceGroup01" -HostPoolName "MYPOOL1" | Select Name

213931-image.png

Get VM status. Note that, Name to be added as vd-0 from VD/vd-0

 Get-AzVM -ResourceGroupName "ResourceGroup01" -name vd-0 -Status

This will show the full status details. At the end you can also see the running status

213922-image.png




--please don't forget to upvote and Accept as answer if the reply is helpful--


image.png (5.6 KiB)
image.png (4.5 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you would like to get the VM running status alone, the following az cli will help. This will filter the only required output

 ((Get-AzVM -ResourceGroupName vd -Name vd-0 -Status).Statuses[1]).DisplayStatus

213954-image.png


0 Votes 0 ·
image.png (5.9 KiB)
ManuPhilip avatar image
0 Votes"
ManuPhilip answered GlennMaxwell-2309 commented

It sounds like you need to assign a bit different permissions to read the running status of Virtual Desktops : rbac




--please don't forget to upvote and Accept as answer if the reply is helpful--

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

will this permission work and please help me with the syntax to check the status.

Microsoft.DesktopVirtualization/*/read

0 Votes 0 ·
ManuPhilip avatar image ManuPhilip GlennMaxwell-2309 ·

I haven't tried the command. Feel free to try the following az cli command and see it works

 az vm get-instance-view --name <vm name> --resource-group <rg name> --query instanceView.statuses[1] --output table 



0 Votes 0 ·

i am getting the below error, will this permission work Microsoft.DesktopVirtualization/*/read

az login
connect-azaccount
Select-AzSubscription -Subscription 'XXXXXX-XXXX-XXXX-XXXX-XXXXXXX' #TEST

PS C:\Windows\system32> az vm get-instance-view --name AVD01 --resource-group "ResourceGroup01" --query instanceView.statuses[1] --output table
az : ERROR: (ResourceGroupNotFound) Resource group 'ResourceGroup01' could not be found.
At line:1 char:1
+ az vm get-instance-view --name AVD01 -- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (ERROR: (Resourc...d not be found.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError


Code: ResourceGroupNotFound
Message: Resource group 'ResourceGroup01' could not be found.

0 Votes 0 ·
ManuPhilip avatar image ManuPhilip GlennMaxwell-2309 ·

Are you querying from the right subscription? Probably the document below helps you to connect the right subscription where your ResourceGroup01 exists

https://docs.microsoft.com/en-us/cli/azure/manage-azure-subscriptions-azure-cli

0 Votes 0 ·

i am querying the correct subscription, i am getting the output when i use the below syntax

Get-AzWvdSessionHost -ResourceGroupName "ResourceGroup01" -HostPoolName "MYPOOL1" | Where-Object -Property AssignedUser -Eq 'user1@mydomain.com'

0 Votes 0 ·
ManuPhilip avatar image ManuPhilip GlennMaxwell-2309 ·

The az cli command I gave before should work, provided we supply the correct RG name found from the WvdSessionHost

0 Votes 0 ·
ManuPhilip avatar image
0 Votes"
ManuPhilip answered ManuPhilip edited

If the above commands are not helping, we need to try with az cli command for getting more details of Azure Virtual Desktop machines deployed.
Make sure that you have installed the required PowerShell modules: Install-Module -Name Az.DesktopVirtualization

Get the host pool details with the list of WVD host pool hosted in the WVD environment. : AzWVDHostPool | Select-Object *
Get-AzWVDSessionHost to get a list of session hosts attached to each host pool

 Get-AzWvdSessionHost -ResourceGroupName $ResGroup -HostPoolName $PoolName | Select-Object *

Hope, the above details will help to frame the required command you are looking for


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.