PS: Azure Credentials

less than 1 minute read

Description:

Currently, I have to write to different functions depending on where I’m pulling passwords from, feel free to use!

To Resolve:

  1. From Azure Key Vault (make sure the script is running as an Azure AD user who has access):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    
    function Get-SNUserName
    {
       $v = Get-AzKeyVaultSecret -VaultName 'my-vault' -Name 'My-Credential'
       $p = $v.SecretValue
       $val = [System.Net.NetworkCredential]::new("", $p).Password
       return $val
    }
          
    function Get-SNPass
    {
       $v = Get-AzKeyVaultSecret -VaultName 'my-vault' -Name 'My-Credential'
       $p = $v.SecretValue
       $val = [System.Net.NetworkCredential]::new("", $p).Password
       return $val
    }
    
  2. Inside the credentials blade inside an Azure Automation Account:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    Function Get-AzureAdminUser
    {
       $cred = Get-AutomationPSCredential -Name 'My-Credential'
       $val = $cred.UserName
       return $val
    }
    
    Function Get-AdminPass
    {
       $cred = Get-AutomationPSCredential -Name 'My-Credential'
       $val = $cred.GetNetworkCredential().Password
       return $val
    }
    

Comments