如何使用Powershell命令或ARM命令启动停止Azure容器实例

时间:2018-10-01 13:49:52

标签: azure containers instance

我知道您可以使用以下命令从Azure CLI启动/停止容器实例 az容器停止--name mycontainer-资源组myResourceGroupVM

但是由于在我的组织中,azure cli给出了“访问被拒绝”错误,所以我想知道如何使用Powershell或ARM进行相同的操作。我无法从文档中获取任何Powershell cmdlet来启动或停止Conrainer实例。请帮忙。

我参考了以下文档: https://docs.microsoft.com/en-us/powershell/module/azurerm.containerinstance/?view=azurermps-6.9.0#container_instances

还有谁能告诉我为什么我得到“访问被拒绝”的信息。所有az(CLI)命令?

2 个答案:

答案 0 :(得分:3)

要使用更新的Powershell“ Az”模块执行此操作,请执行以下操作:

$cg = Get-AzContainerGroup -ResourceGroupName <yourResourceGroupName> -Name <yourContainerGroupName>

Invoke-AzResourceAction -ResourceId $cg.Id -Action start -Force

Action参数可以是startstoprestart

我从Azure资源浏览器获得了这些可能的值:https://resources.azure.com/providers/Microsoft.ContainerInstance/operations

答案 1 :(得分:0)

您可以使用PowerShell cmdlet停止ACI,该cmdlet将如下所示:

a=[]
for x in range(10):
  for y in range(10):
    for z in range(10):
      if x+y+z==3:
        a.append('%r%r%r'%(x,y,z))

a = ['003','012','021','030','102','111','120','201','210','300]

PowerShell cmdlet的结果如下:

enter image description here

此外,它还在Azure门户上显示状态:

enter image description here

相关问题