How to start stop azure container instance using Powershell command or ARM command

≡放荡痞女 提交于 2021-01-27 12:13:59

问题


I know you can start / stop container instance from Azure CLI using below command az container stop --name mycontainer --resource-group myResourceGroupVM

but since in my org azure cli gives "Access is denied" error i want to know how to do same using powershell or ARM. I am unable to get any powershell cmdlet to start or stop conrainer instance from documentation. Please help.

I referred below documentation for same: https://docs.microsoft.com/en-us/powershell/module/azurerm.containerinstance/?view=azurermps-6.9.0#container_instances

Also could anyone tell me why I get "Access is denied." for all az (CLI ) commands?


回答1:


You can use the PowerShell cmdlet to stop the ACI and the cmdlet will like this:

Invoke-AzureRmResourceAction -ResourceGroupName yourResourceGroup -ResourceName yourContainerGroup -Action Stop -ResourceType Microsoft.ContainerInstance/containerGroups

The result of the PowerShell cmdlet like this:

Also, it shows the state on the Azure Portal:




回答2:


To perform this action using the newer Powershell 'Az' modules:

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

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

The Action parameter can be start, stop, restart.

I got those possible values from the Azure Resource Explorer: https://resources.azure.com/providers/Microsoft.ContainerInstance/operations



来源:https://stackoverflow.com/questions/52592629/how-to-start-stop-azure-container-instance-using-powershell-command-or-arm-comma

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!