Created
January 31, 2025 17:27
-
-
Save csdy/18627f9bf2a210ecc33a428c9f75996f to your computer and use it in GitHub Desktop.
Install 7zip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[System.Net.ServicePointManager]::SecurityProtocol = 'Tls,Tls11,Tls12'; | |
function Test-Administrator | |
{ | |
$CurrentUser = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) | |
$CurrentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) | |
} | |
# Download file | |
function Get-File | |
{ | |
param( | |
[Parameter(Mandatory)][string]$FileSource, | |
[Parameter(Mandatory)][string]$FileDestination | |
) | |
Write-Host "`nDownloading to $($FileDestination)" | |
Invoke-WebRequest -Uri $FileSource -UseBasicParsing -OutFile $FileDestination | |
if (!(Test-Path $FileDestination)) { | |
Write-Host "Downloading $FileDestination failed" -Foregroundcolor Red | |
Exit | |
} else { | |
Write-Host "Download complete" -ForegroundColor Green | |
} | |
} | |
# Install file | |
function Install-File | |
{ | |
param($InstallerSource) | |
try { | |
Write-Host "`nInstalling $InstallerSource" | |
$proc = Start-Process -FilePath $InstallerSource -ArgumentList "/quiet /norestart" -Wait -PassThru | |
$proc.waitForExit() | |
Write-Host "Installation complete" -ForegroundColor Green | |
} catch [expression] { | |
Write-Host "Installation failed" -ForegroundColor Red | |
} | |
} | |
# Check privileges | |
if (!(Test-Administrator)) { | |
Write-Host "This script requires elevation (Run as Administrator)" -ForegroundColor Red | |
Exit | |
} | |
$ZipSource = 'https://www.7-zip.org/a/7z2409-x64.msi' | |
$ZipDestination = Join-Path $env:TEMP '7z2409-x64.msi' | |
Get-File $ZipSource $ZipDestination | |
Install-File $ZipDestination |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment