Powershell 启动/停止特定订阅下的所有虚拟机

Powershell 启动/停止特定订阅下的所有虚拟机,powershell,azure,azure-virtual-machine,azure-powershell,Powershell,Azure,Azure Virtual Machine,Azure Powershell,我正在使用Azure Powershell cmdlet启动/停止VM Start-AzureVM [-ServiceName] <String> [-Name] <String> [ <CommonParameters>] Stop-AzureVM [-ServiceName] <String> [-Name] <String> [[-StayProvisioned]] [[-Force]] [ <CommonParamete

我正在使用Azure Powershell cmdlet启动/停止VM

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

Stop-AzureVM [-ServiceName] <String> [-Name] <String> [[-StayProvisioned]] [[-Force]] [ <CommonParameters>]
Start AzureVM[-ServiceName][-Name][]
停止AzureVM[-ServiceName][-Name][-StayProvisionied][-Force][]

是否有命令启动/停止特定订阅下的所有虚拟机,而不是单个虚拟机?如果没有,我正在寻找一个脚本,为每个VM并行运行上述代码多次。

启动AzureVM和停止AzureVM现在支持通配符,允许您并行启动/并行停止同一服务名称内的任何/所有VM。在这里,您可以看到这一点,我刚刚在单个服务中并行启动了几个虚拟机:

现在:如果您想要整个订阅中的所有虚拟机,您可以始终枚举所有服务名称空间,然后在中启动虚拟机。这是一个这样的例子-根据您认为合适的情况对其进行调整,针对特定的数据中心等

枚举服务的示例:

Get-AzureService | Select ServiceName
Get-AzureService | Foreach-Object { Start-AzureVM -ServiceName $_.ServiceName -Name "*" }
现在,我们来做一些事情,而不是仅仅列出服务:

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

注意:我没有测试最后一个,因为我不想启动我所有的虚拟机,但类似的东西应该可以批量“在我订阅的每个服务中启动任何一个虚拟机”。

非常正确-启动AzureVM和停止AzureVM现在支持通配符,允许您并行启动/并行停止同一服务名称内的任何/所有虚拟机

根据问题,无法启动/停止特定订阅下的所有虚拟机。但是,可以在特定服务名称下启动/停止所有VM

启动AzureVM-服务名称“sa12345”
将启动服务名为sa12345的所有azure虚拟机

在使用通配符语法时,我必须将-VM替换为-name并添加-Force开关。Oops-这将教会我在不进行测试的情况下发布代码。:)已编辑的参数名称。这是否为已给出并接受的答案添加了任何新内容?我想不是……我也曾面临同样的挑战。所以,我只是给出了我的意见:)