Azure CLI如何迭代列表

时间:2018-03-28 20:02:01

标签: azure azure-cli2

我需要重新启动Azure Batch中的所有节点。如何使用Azure CLI执行此操作?

基本上我如何在Azure CLI中迭代List / Collection并在该循环中调用命令来停止VM

1 个答案:

答案 0 :(得分:0)

没有一个命令可以执行此操作,但您可以使用脚本重新启动所有节点。如果使用bash shell,则可以使用以下示例:

pools="$(az batch pool list |grep id|awk -F\" '{print $4}')"
for pool in $pools
{
  nodes="$(az batch node list --pool-id $name|grep -F "id\":"|awk -F\" '{print $4}')"
      for node in $nodes
      {
          az batch node reboot --node-id $node --pool-id $pool
      }
}

如果您可以使用Power Shell,则可以使用

重启所有节点
Get-AzureBatchComputeNode -PoolId "MyPool" -BatchContext $Context | Restart-AzureBatchComputeNode -BatchContext $Context

有关此内容的详细信息,请参阅此link