PowerShell - Download and install a file

by
Jeremy Canfield |
Updated: November 06 2023
| PowerShell articles
Here is an example PowerShell script that should download kubectl.exe to C:\Temp\kubectl.exe.
$webclient = New-Object System.Net.WebClient
$url = "https://dl.k8s.io/release/v1.28.3/bin/windows/amd64/kubectl.exe"
$dest = "C:\Temp\kubectl.exe"
try {
$webclient.DownloadFile($src, $dest)
} catch {
Write-Warning "caught the following error"
foreach ($line in $Error) {
Write-Warning $line
}
return
}
Write-Host "Successfully downloaded $url to $file"
And then the following could be used to install the kubectl.exe.
try {
start C:\Temp\kubectl.exe /verysilent
} catch {
Write-Warning "caught the following error"
foreach ($line in $Error) {
Write-Warning $line
}
return
}
Write-Host "Successfully installed kubectl"
Did you find this article helpful?
If so, consider buying me a coffee over at