51 lines
2.0 KiB
PowerShell
51 lines
2.0 KiB
PowerShell
function Install-7Zip {
|
|
<#
|
|
.SYNOPSIS
|
|
|
|
Installs 7-Zip and Adds to the System Path if Needed
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
Param(
|
|
# 7zip doesn't provide a static 'latest stable' download link, so this will require occasional maintenance
|
|
[Parameter(Mandatory = $false)]
|
|
[string]$zipDownloadLink = "http://www.7-zip.org/a/7z1701-x64.msi"
|
|
)
|
|
|
|
$logLead = (Get-LogLeadName);
|
|
Write-Output ("$logLead : Downloading 7Zip from {0}" -f $zipDownloadLink)
|
|
|
|
$msiName = "7Zip.msi"
|
|
$folderDateFormat = Get-Date -Format ddMMyyyy
|
|
$outputFolder = ("C:\Temp\Deploy\7Zip_{0}" -f $folderDateFormat)
|
|
|
|
if (!(Test-Path $outputFolder)) {
|
|
Write-Verbose ("$logLead : Creating 7-Zip Download Folder {0}" -f $outputFolder)
|
|
New-Item $outputFolder -ItemType Directory | Out-Null
|
|
}
|
|
|
|
$downloadedMSI = (Join-Path $outputFolder $msiName)
|
|
if (Test-Path $downloadedMSI) {
|
|
# If a job is rerun, this should prevent downloading the agent again, unless the agent spans a day
|
|
Write-Output ("$logLead : Using Existing MSI from {0}" -f $downloadedMSI)
|
|
}
|
|
else {
|
|
Write-Output ("$logLead : Downloading 7-Zip Installer from {0} to {1}" -f $zipDownloadLink, $downloadedMSI)
|
|
Invoke-WebRequest -Uri $zipDownloadLink -OutFile $downloadedMSI -UseBasicParsing
|
|
}
|
|
|
|
$installParams = ("/i {0} /qn /norestart" -f $downloadedMSI)
|
|
Write-Verbose ("$logLead : Running msiexec.exe with parameters {0}" -f $installParams)
|
|
|
|
$installProcess = Start-Process msiexec.exe -ArgumentList $installParams -NoNewWindow -PassThru -Wait
|
|
Write-Output ("$logLead : Installation completed with exit code {0}" -f $installProcess.ExitCode)
|
|
|
|
$expectedInstallPath = "C:\Program Files\7-Zip"
|
|
if (!(Test-Path $expectedInstallPath)) {
|
|
Write-Warning ("$logLead : Unable to find expected path {0}. Verify the installation was successful and update the path environmental variable as appropriate." -f $expectedInstallPath)
|
|
return
|
|
}
|
|
|
|
Add-DirectoryToPath $expectedInstallPath
|
|
}
|