Created
August 4, 2024 19:59
-
-
Save devenes/1c52bc97da346f8c96e163780e6fe3e1 to your computer and use it in GitHub Desktop.
Installing azcopy and ensuring it is added to the system PATH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$InstallPath = 'C:\AzCopy' | |
# Cleanup Destination | |
if (Test-Path $InstallPath) { | |
Get-ChildItem $InstallPath | Remove-Item -Confirm:$false -Force | |
} | |
# Zip Destination | |
$zip = "$InstallPath\AzCopy.Zip" | |
# Create the installation folder (eg. C:\AzCopy) | |
$null = New-Item -Type Directory -Path $InstallPath -Force | |
# Download AzCopy zip for Windows | |
Start-BitsTransfer -Source "https://aka.ms/downloadazcopy-v10-windows" -Destination $zip | |
# Expand the Zip file | |
Expand-Archive $zip $InstallPath -Force | |
# Move to $InstallPath | |
Get-ChildItem "$($InstallPath)\*\*" | Move-Item -Destination "$($InstallPath)\" -Force | |
#Cleanup - delete ZIP and old folder | |
Remove-Item $zip -Force -Confirm:$false | |
Get-ChildItem "$($InstallPath)\*" -Directory | ForEach-Object { Remove-Item $_.FullName -Recurse -Force -Confirm:$false } | |
# Add InstallPath to the System Path if it does not exist | |
if ($env:PATH -notcontains $InstallPath) { | |
$path = ($env:PATH -split ";") | |
if (!($path -contains $InstallPath)) { | |
$path += $InstallPath | |
$env:PATH = ($path -join ";") | |
$env:PATH = $env:PATH -replace ';;', ';' | |
} | |
[Environment]::SetEnvironmentVariable("Path", ($env:path), [System.EnvironmentVariableTarget]::Machine) | |
#Test if install worked. Should see azcopy.exe utility and a license text file | |
Get-ChildItem -Path $InstallPath | |
} | |
Read-Host -Prompt "Press Enter to exit" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment