我尝试使用 PowerShell 设置自动化作业来重新启动容器实例。但似乎没有内置的 PowerShell 模块/cmdlet 可以提供帮助
我可以使用 azure CLI 重新启动容器实例 ( https://learn.microsoft.com/en-us/cli/azure/container?view=azure-cli-latest#az-container-restart )
az container restart --name <name> --resource-group <group>
有没有办法使用 Powershell 执行相同的操作。
提前致谢
最佳答案
Azure PowerShell不提供直接重启容器实例的建议,但我们可以使用powershell调用Azure管理API来重启容器实例作为解决方法。
3.尝试下面的 powershell 脚本来重新启动容器实例:
$appid = "<application ID we resistered>"
$appSecret= "<application client secret we created>"
$tenant = "<your tenant ID/NAME>"
$resourceGroup = "<resource group>"
$containerInstanceName = "<containerInstances name>"
$subscrptionId = "<subscription ID>"
$body=@{
"grant_type"="client_credentials";
"resource"="https://management.azure.com/";
"client_id"=$appid;
"client_secret"=$appSecret
}
$result=Invoke-RestMethod -Uri "https://login.windows.net/$tenant/oauth2/token" -Method POST -Body $body
$accessToken = $result.access_token
Invoke-RestMethod -Uri "https://management.azure.com/subscriptions/$subscrptionId/resourceGroups/$resourceGroup/providers/Microsoft.ContainerInstance/containerGroups/$containerInstanceName/restart?api-version=2018-10-01" -Method POST -Headers @{"Authorization"="Bearer $accessToken"}
关于azure - 如何使用 powershell 重新启动容器实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59198965/