Azure vm Resource Access Level

I used Azure Resource Manager to create a resource group with multiple virtual machines and other resources.

How can I read the status of a virtual machine for a dedicated virtual machine using Azure Resource Manager (ARM) as a resource in a resource group?

With classic virtual machines, old scripts use:

$vm.InstanceStatus

However, when I switch to Azure Resource Manager mode

Switch-AzureMode AzureResourceManager

The VM object does not recognize .InstanceStatus as a valid variable.

+4
source share
4 answers

The one PowerShell slot you are looking for might look something like this:

Get-AzureRmVM -ResourceGroupName "MyRGName" -Name "MyVmName" -Status | `
    select -ExpandProperty Statuses | `
    ?{ $_.Code -match "PowerState" } | `
    select -ExpandProperty DisplayStatus

VM deallocated, ​​ VM running, .

Get-AzureRmVm, :

Install-Package AzureRM
Install-AzureRM
+4

:

Get-AzureVM -ResourceGroupName <RGName> -Name <VMName> -Status

, , "PowerState/running" ..

, !:)

0

, script, , .

https://miteshc.wordpress.com/2016/02/24/automation-runbook-shutdown-azurearmvm-with-tags/

$ResourceGroup = "RG_Name" $ VMs = Find-AzureRmResource -ResourceGroupNameContains $ResourceGroup | Where-Object {$_.Tags.Name-eq "Autoshutdown" -and $_.Tags.Value -eq "Yes"} Foreach ($VM in $VMs) { $VMStatus = Get-AzureRmVM -ResourceGroupName $ResourceGroup -Name $vm.Name -Status |   -ExpandProperty Statuses |? {$ _. -match "PowerState" } | -ExpandProperty displaystatus

   if($VMStatus -eq "VM Running")
       {
          Write-Output "status of" $vm.Name "is" """$VMStatus"""
          Stop-AzureRmVM -ResourceGroupName $ResourceGroup -Name $vm.Name -Force
       }
       else
       {
          Write-Output "status of" $vm.Name "is" """$VMStatus"""
       }

}

! Mitesh

0
source

You can read the status of the Azure VM provisioning created under ARM using the following PowerShell code:

$vm = Get-AzureRmVM -Name <VMName> -ResourceGroupName <ResourceGroupName>
$vm.ProvisioningState

This is testing with the latest version of Azure PowerShell (1.0.1) released in November 2015.

-1
source

Source: https://habr.com/ru/post/1612957/


All Articles