PowerShell: Download Dot Net 4.7.2

# Illustration: download Dot Net 4.7 Run-time from behind a proxy and showing progress bar

function downloadDotNet472{
# Change these values to reflect your desired downloads
$fileURL = "https://download.microsoft.com/download/6/E/4/6E48E8AB-DC00-419E-9704-06DD46E5F81D/NDP472-KB4054530-x86-x64-AllOS-ENU.exe";
$saveAs = "C:\Temp\dotNet472.exe";

$dotNet472=(Get-ItemProperty "HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full").Release -ge 461808 #Dot Net 4.7.2

if (!($dotNet472)){
# Change this value to reflect your proxy node
$proxy="http://hqproxy:80";

$proxyEnabled=(Get-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings").ProxyEnable
if ($proxyEnabled){
$PSDefaultParameterValues = @{"*:Proxy"="$proxy";}
}

if(!(Get-Module BitsTransfer)){Import-Module BitsTransfer;}

$download=Start-BitsTransfer -Source $fileURL -Destination $saveAs -Asynchronous;

While( ($download.JobState.ToString() -eq 'Transferring') -or ($download.JobState.ToString() -eq 'Connecting') ){
$percent = [int](($download.BytesTransferred*100) / $download.BytesTotal)
Write-Progress -Activity "Downloading..." -CurrentOperation "$percent`% complete"
}
Complete-BitsTransfer -BitsJob $download
$inlineInvokeString="$saveAs /passive /norestart /log C:\Temp\dotNet472_install_log.htm";
iex $inlineInvokeString;
}
else{"Dot Net 4.7.2 or higher is already present in this Windows machine.";}
}
downloadDotNet472

Leave a Reply

Your email address will not be published. Required fields are marked *