powershell - 如何检测Azure Powershell session 是否已过期?

标签 powershell authentication azure

我正在编写一个 Azure PowerShell 脚本,为了登录 Azure,我调用 Add-AzureAccount,这将弹出一个浏览器登录窗口。

我想知道检查身份验证凭据是否已过期以及是否应该再次调用 Add-AzureAccount 的最佳方法是什么?

我现在要做的就是调用 Get-AzureVM 并查看 $? 是否等于 $False。对我来说听起来有点老套,但似乎有效。如果订阅没有部署任何虚拟机,它仍然有效吗?

最佳答案

Azure RM,但这将检查是否有事件帐户,否则会弹出提示。

if ([string]::IsNullOrEmpty($(Get-AzureRmContext).Account)) {Login-AzureRmAccount}

干杯

关于powershell - 如何检测Azure Powershell session 是否已过期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28105095/

相关文章:

Laravel 5.6 - 在 Controller 中按名称获取路由

asp.net-mvc - 系统架构 : How to Use the same Banner ( like google banner ) in multiple different websites hosted in different domains or subdomains )

android - Quickblox:如何查明用户是否在线?

azure - 尝试访问已部署的函数时,KUDU 给出禁止错误 - 403

azure - 如何与 New-AzureRmResourceGroupDeployment cmdlet 一起传递额外参数

azure - DocumentDb "where"带有数学表达式的子句

Powershell 脚本作为可执行文件给出 "wrong",在 Bamboo 中给出返回码 -1

powershell - 无法从函数内部修改脚本范围的变量

powershell - 在 PowerShell 中对齐 Select-String 的输出

arrays - -join ";"是如何工作的?