PowerShell: Connect to Azure CLI

# Set PSGallery as trusted to bypass prompts
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted -WarningAction Silently
# Configure PSSession to authenticate to intranet proxy, if exists
(New-Object System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
# Install Azure CLI
Install-Module -Name Az -AllowClobber
# Set Credentials
$password=ConvertTo-SecureString -AsPlainText "PASSWORD" -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password
# Connect to Azure the normal way
Connect-AzAccount -Credential $cred
# Connect to Azure the funky way
Connect-AzAccount -Credential $cred -Tenant $tenant -ServicePrincipal
# Connect to Azure with 2nd Factor Authenticaton

Leave a Reply

Your email address will not be published. Required fields are marked *