KlaymenDK
KlaymenDK

Reputation: 724

Using Azure Powershell to shutdown VM created with no Cloud Service Name

This isn't a duplicate of this question, because that solution no longer works after MS made a change breaking backwards compatibility.

My need is to programmatically (via Azure Powershell) start/stop VM's that were created programmatically (via Azure Powershell). The documentation says I need to supply a "service name", but I cannot find any reference to how I can obtain that from a VM:

Stop-AzureVM -ServiceName $hostname -Name $hostname
Start-AzureVM -ServiceName $hostname -Name $hostname

The documentation also suggests using Get-AzureService and (I think) allows me to supply a Profile instead of a Service. However, using Select-AzureRmProfile I can only obtain a Microsoft.Azure.Commands.Profile.Models.PSAzureProfile, but Get-AzureService requires a Microsoft.Azure.Commands.Profile.Models.PSAzureSMProfile. I am stuck.

Help?

Upvotes: 1

Views: 897

Answers (2)

Neil Mackenzie
Neil Mackenzie

Reputation: 2847

There are two control planes in Azure: Azure Service Management (ASM) and Azure Resource Manager (ARM). All VMs created using ASM have cloud service names as well as a VM name. I suspect you created an ARM VM for which a resource group name takes the place of a cloud service name. ARM PowerShell cmdlets all have AzureRm in the name instead of Azure.

In ARM you use the the following:

Start-AzureRmVM -Name $vmName -ResourceGroupName $resourceGroupName

Stop-AzureRmVM -Name $vmName -ResourceGroupName $resourceGroupName

Upvotes: 3

Dewi Jones
Dewi Jones

Reputation: 825

If you know the name rather than the service name you could do...

Get-AzureVM | Where {$_.Name -eq "VMNAME"} | Stop-AzureVM

But that is completely dependant on whether you have the name rather than service name of the VM, your question does not state otherwise so im assuming here you do! :D

However should this not work please comment with what details you have of the VM and ill see what i can do.

Upvotes: 1

Related Questions