我想讓我的powershell腳本檢查用戶帳戶憑據是否過期,如果是,請調用Add-AzureAccount
commandlet。這樣用戶可以重新輸入憑據而不是看到錯誤。Azure Powershell檢查過期的憑據
有沒有辦法使用Azure Powershell SDK檢查到期日期?
我想讓我的powershell腳本檢查用戶帳戶憑據是否過期,如果是,請調用Add-AzureAccount
commandlet。這樣用戶可以重新輸入憑據而不是看到錯誤。Azure Powershell檢查過期的憑據
有沒有辦法使用Azure Powershell SDK檢查到期日期?
當前最新版本的Azure PowerShell模塊沒有任何命令來檢查Azure用戶帳戶是否過期。
您可以最近得到的是使用Get-AzureAccount -Name來檢查您是否已將帳戶添加到PowerShell Azure配置文件。
你可以做下面有對帳戶到期的支票在PowerShell會話
$Account = Get-AzureAccount -Name "[email protected]"
if (!$Account)
{
Add-AzureAccount
}
希望這有助於!
我一直使用try /成功趕上,例如調用Get-AzureWebsite:
$websiteName = "..."
Try
{
$website = Get-AzureWebsite -Name $websiteName -ErrorAction Stop;
}
Catch [System.ArgumentException]
{
if ($_.Exception.Message -eq "Your Azure credentials have not been set up or have expired, please run Add-AzureAccount to set up your Azure credentials.")
{
Add-AzureAccount;
Write-Host "Azure account set, re-run script to continue."
}
else
{
Write-Host $_.Exception.Message;
}
}
我敢肯定有一個不那麼脆弱的方式不是檢查異常消息所以認爲這將開始一種方法。
我使用以下腳本從文件加載憑據,從而跳過UI提示。如果該文件不存在,或者憑證已過期,則系統會提示用戶,並在下次保存憑證。
if (Test-Path ("{0}/azure-credentials.json" -f (Get-Location)))
{
$Null = Select-AzureRmProfile -Path ("{0}/azure-credentials.json" -f (Get-Location))
Try
{
Get-AzureRMManagedSubscription
} Catch {
Login-AzureRmAccount
Save-AzureRmProfile -Path ("{0}/azure-credentials.json" -f (Get-Location))
}
} else {
Login-AzureRmAccount
Save-AzureRmProfile -Path ("{0}/azure-credentials.json" -f (Get-Location))
}
此命令不能用於檢查憑證過期。我能夠使用Get-AzureAccount命令獲得一個帳戶,但是當腳本繼續創建新的服務總線命名空間時,它會通知我該憑據尚未設置或已過期。 – Lichader