Posted On April 2, 2019

PowerShell: Download Dot Net 4.7.2

kimconnect 0 comments
blog.KimConnect.com >> Codes , Windows >> 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 *

Related Post

Error: 502 Gateway Error

Explanation: 502 Gateway Error generally means connection problems with an upstream proxy. In this instance,…

How to globally edit PING monitor timing (to 30 seconds)

IPMonitor uses “monitors” in order to test a machine’s status for different components. The PING…

Run Windows Commands Remotely

# RPC WMIC /node:SERVER1 process call create 'powershell.exe' # WinRM winrs -r:SERVER1 powershell.exe # Systernals psexec //SERVER1 powershell.exe
Other project: DragonCoin.com