diff --git a/Application Management/Install-Chrome.ps1 b/Application Management/Install-Chrome.ps1 index e941887..00e355f 100644 --- a/Application Management/Install-Chrome.ps1 +++ b/Application Management/Install-Chrome.ps1 @@ -1,33 +1,58 @@ Write-Host 'Please allow several minutes for the install to complete. ' + +# Install Google Chrome x64 on 64-Bit systems? $True or $False +$Installx64 = $True + +# Define the temporary location to cache the installer. +$TempDirectory = "$ENV:Temp\Chrome" + +# Run the script silently, $True or $False +$RunScriptSilent = $True + +# Set the system architecture as a value. +$OSArchitecture = (Get-WmiObject Win32_OperatingSystem).OSArchitecture + # Exit if the script was not run with Administrator priveleges $User = New-Object Security.Principal.WindowsPrincipal( [Security.Principal.WindowsIdentity]::GetCurrent() ) if (-not $User.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator )) { Write-Host 'Please run again with Administrator privileges.' -ForegroundColor Red - Read-Host 'Press [Enter] to exit' + if ($RunScriptSilent -NE $True){ + Read-Host 'Press [Enter] to exit' + } exit } + Function Download-Chrome { Write-Host 'Downloading Google Chrome... ' -NoNewLine # Test internet connection if (Test-Connection google.com -Count 3 -Quiet) { - $Link = 'http://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi' + if ($OSArchitecture -eq "64-Bit" -and $Installx64 -eq $True){ + $Link = 'http://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise64.msi' + } ELSE { + $Link = 'http://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi' + } + # Download the installer from Google try { - New-Item -ItemType Directory 'C:/TEMP' -Force | Out-Null - (New-Object System.Net.WebClient).DownloadFile($Link, 'C:/TEMP/Chrome.msi') + New-Item -ItemType Directory "$TempDirectory" -Force | Out-Null + (New-Object System.Net.WebClient).DownloadFile($Link, "$TempDirectory\Chrome.msi") Write-Host 'success!' -ForegroundColor Green } catch { Write-Host 'failed. There was a problem with the download.' -ForegroundColor Red - Read-Host 'Press [Enter] to exit' + if ($RunScriptSilent -NE $True){ + Read-Host 'Press [Enter] to exit' + } exit } } else { Write-Host "failed. Unable to connect to Google's servers." -ForegroundColor Red - Read-Host 'Press [Enter] to exit' + if ($RunScriptSilent -NE $True){ + Read-Host 'Press [Enter] to exit' + } exit } } @@ -36,14 +61,17 @@ Function Install-Chrome { Write-Host 'Installing Chrome... ' -NoNewline # Install Chrome - $ExitCode = (Start-Process msiexec "/i C:/TEMP/Chrome.msi /qn" -Wait -PassThru).ExitCode + $ChromeMSI = """$TempDirectory\Chrome.msi""" + $ExitCode = (Start-Process -filepath msiexec -argumentlist "/i $ChromeMSI /qn /norestart" -Wait -PassThru).ExitCode if ($ExitCode -eq 0) { Write-Host 'success!' -ForegroundColor Green } else { Write-Host "failed. There was a problem installing Google Chrome. MsiExec returned exit code $ExitCode." -ForegroundColor Red Clean-Up - Read-Host 'Press [Enter] to exit' + if ($RunScriptSilent -NE $True){ + Read-Host 'Press [Enter] to exit' + } exit } } @@ -53,10 +81,10 @@ Function Clean-Up { try { # Remove the installer - Remove-Item C:/TEMP/Chrome.msi -ErrorAction Stop + Remove-Item "$TempDirectory\Chrome.msi" -ErrorAction Stop Write-Host 'success!' -ForegroundColor Green } catch { - Write-Host 'failed. You will have to remove the installer yourself from C:\TEMP\.' -ForegroundColor Yellow + Write-Host "failed. You will have to remove the installer yourself from $TempDirectory\." -ForegroundColor Yellow } } @@ -64,4 +92,6 @@ Download-Chrome Install-Chrome Clean-Up -Read-Host 'Install complete! Press [Enter] to exit' \ No newline at end of file +if ($RunScriptSilent -NE $True){ + Read-Host 'Install complete! Press [Enter] to exit' +} \ No newline at end of file