Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions Application Management/Install-Chrome.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}
Expand All @@ -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
}
}
Expand All @@ -53,15 +81,17 @@ 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
}
}

Download-Chrome
Install-Chrome
Clean-Up

Read-Host 'Install complete! Press [Enter] to exit'
if ($RunScriptSilent -NE $True){
Read-Host 'Install complete! Press [Enter] to exit'
}