Posted On July 17, 2019

PowerShell: Connect to Azure CLI

kimconnect 0 comments
blog.KimConnect.com >> Codes , Virtualization >> PowerShell: Connect to Azure CLI
# Set PSGallery as trusted to bypass prompts
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted -WarningAction Silently
Continue
# 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
$username="[email protected]"
$password=ConvertTo-SecureString -AsPlainText "PASSWORD" -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password
$tenant="xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx"
# 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 *

Related Post

Basic HTML and HTML5: Add a Submit Button to a Form

<h2>CatPhotoApp</h2><main><p>Click here to view more <a href="#">cat photos</a>.</p><a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying…

PowerShell: Auto Login to WordPress and Update Gold Prices WooCommerce Plugin

# API URI - these are examples, only $goldPriceApi='https://dragoncoin.com/XAU/USD' $silverPriceApi='https://dragoncoin.com/XAG/USD' $platinumApi='https://dragoncoin.com/XPT/USD' $palladiumApi='https://dragoncoin.com/XPD/USD' # Wordpress WooCommerce…

PowerShell: Sorting an Array of Strings as Numbers

This is a useful function to sort a list of computer names. The built-in sorting…