PowerShell AzureRM Commands - Expiration Exception in Save-AzureRMProfile

I automated the deployment of Azure using commands AzureRM. These commands need a login, so I tried to provide a saved profile using Save-AzureRMProfile/ Select-AzureRMProfile.

However, after a while, it seems that the deadline is about to expire and I need to log in again. I want to run my script automatically on a schedule, so manual re-entry is not a solution.

How can I avoid profile expiration?

+2
source share
1 answer

, , . ( , ) -

Add-AzureRmAccount pscredential. , .

pscredential save, , pscredential , , , pscredential.

$key = New-Object byte[](32)
$rng = [System.Security.Cryptography.RNGCryptoServiceProvider]::Create()
$rng.GetBytes($key)

. , , .

$cred = Get-Credential
$SecureStringWithKey = $cred.Password | ConvertFrom-SecureString -Key $key

base64 ..

$base64key = [Convert]::ToBase64String($key)  

$key  = [System.Convert]::FromBase64String($base64key)

SecureString .

$secureStringPassword = $AuthObject.SecureStringWithKey | ConvertTo-SecureString -Key $key 
$cred = new-object -typename System.Management.Automation.PSCredential `
             -argumentlist $Username, $secureStringPassword

Add-AzureRmAccount -Credential $cred

, psobject ( , tenantid pscredential), json, . , json , , , .

+4

Source: https://habr.com/ru/post/1675846/


All Articles