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

Simple Active Directory & DNS Synchronization Script

@echo offGOTO push_or_pull:push_or_pullset /p action="Type in Push, Pull, or Quit. Press Enter for default action…

Active Directory Audit Using AD Tidy

1. Clean up user accounts Download AD Tidy: https://www.cjwdev.com/Software/ADTidy/Download.html Run: "C:\Program Files\Cjwdev\AD Tidy Free Edition\ADTidy.exe"…

PowerShell: Get Size On Disk and Discover Largest Files in a Given Directory

# getSizeOnDisk-v0.01.ps1# Set variables$parentDirectory="C:\"$depth=4$topX=10$excludeDirectories="C:\Windows","C:\Program Files","C:\Program Files (x86)"$clusterSizeOfNetworkShare=8192# sanitateif($depth -le 1){$depth=1}################################## Excuting Program as an Administrator…