I'm using Azure Powershell cmdlets to start/stop VMs.

Start-AzureVM [-ServiceName] <String> [-Name] <String> [ <CommonParameters>]

Stop-AzureVM [-ServiceName] <String> [-Name] <String> [[-StayProvisioned]] [[-Force]] [ <CommonParameters>]

Is there a command to start/stop all VMs under a specific subscription rather than a single VM? If not, I'm looking for a script to run above code multiple times in parallel for each VM.

有帮助吗?

解决方案

Start-AzureVM and Stop-AzureVM now support wildcards, allowing you to parallel-start / parallel-stop any/all VMs within the same service name. Here, you can see this in action, where I just started a few VMs in a single service, in parallel:

Calling Start-AzureVM

Parallel operation, seen in portal

Now: If you wanted all VMs in the entire subscription, you could always enumerate all of your service namespaces, then start the VMs within. This is an example of that - tweak it as you see fit, for particular datacenter, etc.

Example of enumerating services:

Get-AzureService | Select ServiceName

Now to do something with that, instead of just listing the services:

Get-AzureService | Foreach-Object { Start-AzureVM -ServiceName $_.ServiceName -Name "*" }

Note: I didn't test that last one, as I didn't feel like starting all my VMs, but something like that should work for you as a bulk "start ever single VM in every single service in my subscription."

其他提示

Very True- Start-AzureVM and Stop-AzureVM now support wildcards, allowing you to parallel-start / parallel-stop any/all VMs within the same service name.

As per the question start/stop all VMs under a specific subscription is not possible. However start/stop all VMs under a specific service name is possible.

Start-AzureVM -ServiceName "sa12345" will start all azure vms under service name sa12345

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top