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

PowerShell: Add Accounts into Local Administrators Group

# addAccountToLocalAdmins.ps1# Requires: PowerShell Version 4.0+$accountToAdd='ServerAdmins'$groupName="Administrators"$servers=@( "CONCU1", 'CONCU2', 'CONCU100', 'CONCU80665', 'CONCU6547354', 'CONWHAT989', 'CONCU3')$servers|%{ $session=new-pssession $_…

JavaScript: Build a Tribute Page

Demo: https:// codepen.io/dragoncoin/pen/EZJxYY HTML Code: <html><head> <body> <img src="http://www.animationxpress.com/wp-content/uploads/2015/10/Mahatma-Gandhi.jpg"> <h1>Mahatma Gandhi</h1> <div class="hidden"> <h2>"You must…

PowerShell: Backup Dynamics CRM Organization Database

# backupCrmOrgDatabase.ps1 # This script is to be invoked in the context of the Administrator…