Skip to content

Instantly share code, notes, and snippets.

@ylerner43
Last active September 16, 2022 14:04
Show Gist options
  • Save ylerner43/94bb716097d66ceea042f2b6c2719305 to your computer and use it in GitHub Desktop.
Save ylerner43/94bb716097d66ceea042f2b6c2719305 to your computer and use it in GitHub Desktop.
$LocalTempDir = $env:TEMP;
$ChromeInstaller = "ChromeInstaller.exe";
$ChromeVersion = "Empty";
Function Get-ChromeVersion {
# $IsWindows will PowerShell Core but not on PowerShell 5 and below, but $Env:OS does
# this way you can safely check whether the current machine is running Windows pre and post PowerShell Core
Try {
(Get-Item (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe' -ErrorAction Stop).'(Default)').VersionInfo.FileVersion;
}
Catch {
Throw "Google Chrome not found in registry";
}
}
#Get Version if exists
$ChromeVersion = Get-ChromeVersion -ErrorAction Stop;
Write-Output "Google Chrome version: $ChromeVersion";
If (![string]::IsNullOrEmpty($ChromeVersion)) {
Write-Output "Google Chrome version $ChromeVersion found on machine";
}
else{
#Download Chrome and install
(new-object System.Net.WebClient).DownloadFile('http://dl.google.com/chrome/install/375.126/chrome_installer.exe', "$LocalTempDir\$ChromeInstaller");
& "$LocalTempDir\$ChromeInstaller" /silent /install;
$Process2Monitor = "ChromeInstaller";
Do { $ProcessesFound = Get-Process | ?{$Process2Monitor -contains $_.Name} | Select-Object -ExpandProperty Name;
"Checking if process still running.."
If ($ProcessesFound) { "Still running: $($ProcessesFound -join ', ')" | Write-Host; Start-Sleep -Seconds 2 }
else { rm "$LocalTempDir\$ChromeInstaller" -ErrorAction SilentlyContinue -Verbose } }
Until (!$ProcessesFound)
}
"Completed"
$url = "https://c2rsetup.officeapps.live.com/c2r/downloadVS.aspx?sku=community&channel=Release&version=VS2022&source=VSLandingPage&includeRecommended=true"&cid=2030%22:25557b80-14ac-4350-85d4-21ba0e748dde"
New-Item -Path 'C:\VS_Download' -ItemType Directory -force
$downloadPath = "C:\VS_Download"
$filePath = "C:\VS_Download\vsSetup.exe"
Write-Host "Downloading VS Installer.." -ForegroundColor Yellow
#remove file if exists
if (Test-Path $filePath) { Remove-Item $filePath}
Invoke-WebRequest -URI $url -OutFile $filePath
Write-Host "Download Completed!.." -ForegroundColor Green
#Show-InstallationProgress "Installing Visual Studio Community 2019. This may take some time. Please wait..."
$workloadArgument = @(
'--add Microsoft.Net.Component.4.7.1.SDK'
'--add Microsoft.VisualStudio.Component.Windows10SDK.17134'
'--add Microsoft.Net.Component.4.7.1.TargetingPack'
)
$optionsAddLayout = [string]::Join(" ", $workloadArgument )
$optionsQuiet = "--quiet"
$optionsIncludeRecommended = "--includeRecommended"
$vsOptions = @(
$optionsAddLayout,
$optionsIncludeRecommended,
$optionsQuiet
)
$process = Start-Process -FilePath $filePath -ArgumentList $vsOptions -PassThru
for($i = 0; $i -le 300; $i = ($i + 1) % 100)
{
Write-Progress -Activity "Installer" -PercentComplete $i -Status "Installing"
Start-Sleep -Milliseconds 1000
Write-Host "Has Process been completed: " + $process.HasExited
if ($process.HasExited) {
Write-Progress -Activity "Installer" -Completed
break
}
}
Write-Host "Completed" -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment