Comments on: How to Install Azure CLI on Windows (one-liner) https://www.thomasmaurer.ch/2019/07/how-to-install-azure-cli-on-windows-one-liner/ Cloud and Datacenter Blog focusing on Microsoft Azure Sat, 20 Feb 2021 08:21:12 +0000 hourly 1 https://wordpress.org/?v=6.4.1 By: dcasota https://www.thomasmaurer.ch/2019/07/how-to-install-azure-cli-on-windows-one-liner/#comment-848221 Sat, 20 Feb 2021 08:21:12 +0000 https://www.thomasmaurer.ch/?p=12777#comment-848221 Hi @Moueen,
try this

Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi
Start-Process msiexec.exe -Wait -ArgumentList “/a AzureCLI.msi /qb TARGETDIR=$env:APPDATA\azure-cli /quiet”

if (!($env:Path -like ‘*CLI2\wbin*’))
{
$Remove = ‘C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin’
$env:Path = ($env:Path.Split(‘;’) | Where-Object -FilterScript {$_ -ne $Remove}) -join ‘;’
}
$env:path=”$env:APPDATA\azure-cli\Microsoft SDKs\Azure\CLI2\wbin;”+$env:path
rm .\AzureCLI.msi
az –version 2>$null

And, with az version 2.11 and above you may use
az upgrade –yes –all 2>&1 | out-null

]]>
By: Moueen https://www.thomasmaurer.ch/2019/07/how-to-install-azure-cli-on-windows-one-liner/#comment-843381 Tue, 12 Jan 2021 01:08:50 +0000 https://www.thomasmaurer.ch/?p=12777#comment-843381 Hello Thomas,

Thank for sharing the article.

I am working on one automated process to upload a file using az CLI to Azure blob.
When the user run’s the script for the first time if there is no azure CLI installed on the user machine. I am installing(find below code), But the requirement here is after installing azure CLI from PowerShell and it should not restart and allow the user to execute the az login command.

Code for your reference :
Function Set-AzModule(){
$isAzureCliInstalled = Azure-CLI-Installed
Set-AzCopyVariables
if (!$isAzureCliInstalled) {
Write-Log “Trying to install Microsoft Azure CLI”
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList ‘/I AzureCLI.msi /quiet’; rm .\AzureCLI.msi
$isAzureCliInstalled = Azure-CLI-Installed;

if (!$isAzureCliInstalled) {
Write-Log -message “Unable to install Microsoft Azure CLI”
}
else {
Write-Log -message “Microsoft Azure CLI installed successfully”
az login
## Here the command is failing power shell not able to find the az module
}
}
}

Function Azure-CLI-Installed()
{
# Check Microsoft Azure CLI is installed or not.
return (Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
Where { $_.DisplayName -eq “Microsoft Azure CLI” }) -ne $null
}

Please help me on this.

]]>