Closed asktechsupport closed 3 months ago
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
# Define the URL for the latest Chrome installer
$chromeInstallerUrl = "https://www.google.com/chrome/next-steps.html?statcb=0&installdataindex=empty&defaultbrowser=0#"
# Define the local path where the installer will be saved
$installerPath = "$env:TEMP\chrome_installer.exe"
# Function to download a file with a progress bar
function Download-FileWithProgress {
param (
[string]$url,
[string]$destination
)
# Create a web client
$webClient = New-Object System.Net.WebClient
# Set up an event handler to update the progress bar
$webClient.DownloadProgressChanged += {
param($sender, $e)
# Calculate percent complete and display progress bar
$percentComplete = $e.ProgressPercentage
Write-Progress -Activity "Downloading Chrome" -Status "$percentComplete% Complete" -PercentComplete $percentComplete
}
# Download the file
$webClient.DownloadFile($url, $destination)
}
# Download the Chrome installer
Download-FileWithProgress -url $chromeInstallerUrl -destination $installerPath
# Simulate installation process with a progress bar
$totalSteps = 100
for ($i = 1; $i -le $totalSteps; $i++) {
# Update the progress bar
$percentComplete = ($i / $totalSteps) * 100
Write-Progress -Activity "Installing Chrome" -Status "Progress: $percentComplete% Complete" -PercentComplete $percentComplete
# Simulate some work with Start-Sleep
Start-Sleep -Milliseconds 30
}
# Install Chrome silently
Write-Host "Starting Chrome installation..."
Start-Process -FilePath $installerPath -ArgumentList "/silent /install" -NoNewWindow -Wait
# Indicate that the installation is complete
Write-Host "Chrome installation completed successfully!"
# Clean up the installer
Remove-Item -Path $installerPath -Force
# Set the execution policy to unrestricted for the current session
Set-ExecutionPolicy Unrestricted -Scope Process -Force
# Define the URL for the Firefox installer
$InstallerUrl = "https://download.mozilla.org/?product=firefox-latest&os=win64&lang=en-GB"
# Define the local path where the installer will be saved
$installerPath = "$env:TEMP\firefox_installer.exe"
# Function to download a file with a progress bar
function Download-FileWithProgress {
param (
[string]$url,
[string]$destination
)
# Create a web client
$webClient = New-Object System.Net.WebClient
# Set up an event handler to update the progress bar
$webClient.DownloadProgressChanged += {
param($sender, $e)
# Calculate percent complete and display progress bar
$percentComplete = $e.ProgressPercentage
Write-Progress -Activity "Downloading Application" -Status "$percentComplete% Complete" -PercentComplete $percentComplete
}
# Download the file
try {
$webClient.DownloadFile($url, $destination)
} catch {
Write-Error "Failed to download file. Error: $_"
exit 1
}
}
# Download the installer
Download-FileWithProgress -url $InstallerUrl -destination $installerPath
# Verify that the installer was downloaded successfully
if (Test-Path $installerPath) {
Write-Host "Download completed successfully. Starting installation..."
# Simulate installation process with a progress bar
$totalSteps = 100
for ($i = 1; $i -le $totalSteps; $i++) {
# Update the progress bar
$percentComplete = ($i / $totalSteps) * 100
Write-Progress -Activity "Installing Firefox..." -Status "Progress: $percentComplete% Complete" -PercentComplete $percentComplete
# Simulate some work with Start-Sleep
Start-Sleep -Milliseconds 30
}
# Install Firefox silently
try {
Start-Process -FilePath $installerPath -ArgumentList "/S" -NoNewWindow -Wait
Write-Host "Firefox installation completed successfully!"
} catch {
Write-Error "Installation failed. Error: $_"
} finally {
# Clean up the installer
Remove-Item -Path $installerPath -Force
}
} else {
Write-Error "Installer file was not found. Download might have failed."
}
68
Resolved
Template when installing from web
Instructions