Jump to content

Install 7-Zip with PowerShell


Recommended Posts

I made a install script for 7-Zip to do a Silent install and clean if needed.

Improvements are welcome!

When a new version of 7-Zip comes out, just change the 7z1604-x64.msi to the new value.

# Silent Install 7-Zip
# http://www.7-zip.org/download.html 

# Path for the workdir
$workdir = "c:\installer\"

# Check if work directory exists if not create it

If (Test-Path -Path $workdir -PathType Container)
{ Write-Host "$workdir already exists" -ForegroundColor Red}
ELSE
{ New-Item -Path $workdir  -ItemType directory }

# Download the installer

$source = "http://www.7-zip.org/a/7z1604-x64.msi"
$destination = "$workdir\7-Zip.msi"

# Check if Invoke-Webrequest exists otherwise execute WebClient

if (Get-Command 'Invoke-Webrequest')
{
     Invoke-WebRequest $source -OutFile $destination
}
else
{
    $WebClient = New-Object System.Net.WebClient
    $webclient.DownloadFile($source, $destination)
}

Invoke-WebRequest $source -OutFile $destination 

# Start the installation

msiexec.exe /i "$workdir\7-Zip.msi" /qn

# Wait XX Seconds for the installation to finish

Start-Sleep -s 35

# Remove the installer

rm -Force $workdir\7*

 

Link to post
Share on other sites
  • 1 year later...

The Script now installs the latest Version of 7 Zip by by reading the Releasenumber from SourceForge. It now Accepts Spaces at the workdirectory, and writes What its Doing to the User.

 

 

#Requires -Version 5.0

Write-Verbose "Getting latest Version" -Verbose

class SourceForge {
    [string]        $Project = $Null
    [PSCustomObject]$LatestRelease = $Null

    
    SourceForge([string] $project) {
        $this.Project = $project
        $this.GetLatestRelease()
    }

    
    [void] GetLatestRelease() {
        $originalSecurityProtocol = [Net.ServicePointManager]::SecurityProtocol
        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
        
        $this.GetLatestRelease('https://sourceforge.net/projects/{0}/best_release.json')
        
        [Net.ServicePointManager]::SecurityProtocol = $originalSecurityProtocol
    }


    [void] GetLatestRelease([string] $url) {
        $url = $url -f @($this.Project)
        Write-Debug "[SourceForge].GetLatestRelease URL: ${url}"
        $this.LatestRelease = ConvertFrom-Json (Invoke-WebRequest $url -UseBasicParsing).Content
    }

    
    [string] LatestVersion() {
        if (-not $this.LatestRelease) {
            $this.GetLatestRelease()
        }

        return $this.LatestRelease.release.filename.Split('/')[2]
    }

    [hashtable] LatestHash() {
        if (-not $this.LatestRelease) {
            $this.GetLatestRelease()
        }

        return @{
            'Algorithm' = 'MD5';
            'Hash' = $this.LatestRelease.release.md5sum.ToUpper();
        }
    }
}

$7zip = [SourceForge]::new('sevenzip')

$Version = $7zip.LatestVersion() 

# get Numbers from String

$Version = $Version -replace("[^\d]","")



# Silent Install 7-Zip
# http://www.7-zip.org/download.html 

# Path for the workdir
$workdir = 'C:\Installer'

Write-Verbose "Creating Working Directory: $workdir" -Verbose

# Check if work directory exists if not create it

If (!(Test-Path -Path $workdir -PathType Container))
{ New-Item -Path $workdir  -ItemType directory }

# Download the installer
Write-Verbose "Downloading 7-Zip Version $Version" -Verbose

$source = "http://www.7-zip.org/a/7z$Version-x64.exe"

$destination = "$workdir\7-Zip.exe"

# Check if Invoke-Webrequest exists otherwise execute WebClient

if (Get-Command 'Invoke-Webrequest')
{
     Invoke-WebRequest $source -OutFile $destination
}
else
{
    $WebClient = New-Object System.Net.WebClient
    $webclient.DownloadFile($source, $destination)
}

Invoke-WebRequest $source -OutFile $destination 

# Start the installation

Write-Verbose "Install 7-Zip Version $Version" -Verbose

$UnattendedArgs='/S'
$File='"' + $workdir + '\7-zip.exe"'

(Start-Process $File $UnattendedArgs -Wait -Passthru).ExitCode

# Remove the installer

Write-Verbose "Delete Working Directory" -Verbose

Remove-Item $workdir -Recurse -Force 

 

 

 

Link to post
Share on other sites
  • 4 weeks later...

If you look into using chocolatey, it works quite nicely in Pulseway to install apps:

choco install 7zip

You would have to install chocolatey on the endpoint, but then you can use it to script installs, uninstalls and change Windows settings as well.

Link to post
Share on other sites
  • 3 months later...

Hay BartB, I agree, I followed your advise and it works well, I'm worried however about the source files, It would be very cool if a group of us Pulseway users worked to as a team to setup our own file hosting of secure files, interested in starting something up?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By Canadian Dental Services
      Hi all,
      I recently did a clean upgrade to Windows 10 on 2 WKSTs previously running Windows 7 with Pulseway installed.  I am now at a loss as to how to re-add these units to my Pulseway instance.
      I see they are still showing up in the “Deployment Successful” tab under “Discovery & Deployment”.
      Is there a way to re-add these units without manually installing the Pulseway app on these WKSTs?
    • By RingTailedLemur7
      Hello, I have a question about the Pulseway app. When the pc is on all of the commands work great and are perfect for managing the pc. But I am attempting to turn on my pc when I am away from my home and then be able to fully control it like I was there. The issue is how the wake up command from sleep or from powered down will not work even when on my home network. How can I fix this. Also a side question, is there a way I would be able to see a live view of the screen or does it only allow screenshots of the screen. Thanks
    • By DQuiram
      We reinstalled Pulseway on a re-imaged system and after the install we noticed issues. In the patch mgmt section, the status was "assign failed" in red. We rebooted the system and then the service was not starting. We checked the service, it was set to start automatically and in the event log it was generating this error: "Service cannot be started.  The handle is invalid"  We removed the system from Pulseway, uninstalled, and reinstalled. Service is starting normally, but still getting the same issue of the patch policy failing to assign. I tried moving the system to another group that did not have a patch policy at all and got the same result. 
    • By Brant
      I've implemented a script that retrieves and stores the Windows Build Version number to a custom field in the system overview.   It works fine on MOST systems.  However, there are a small number systems that are unable to run the script.  The error message displayed includes: Start-Process : This command cannot be run due to the error: The system cannot find the file specified.
      I used the "Insert Output Variable Code" in the script and verified that it includes the inserted text "Start-Process -FilePath "$env:PWY_HOME\CLI.exe" -ArgumentList ("setVariable  .....".
      For some reason, a few systems do not seem to have the environment variable PWY_HOME set.
      It appears that these systems are using the Enable PowerShell User Impersonation option under Pulseway Manger > Settings > Runtime.
      What is the easiest way to make sure that all of my systems have the PWY_HOME variable set so that any future scripts will not fail because of a missing environment variable?
      Thanks,
      Brant
    • By devansh.gohil
      I had installed Pulseway and then wanted to delete it but I was not able to find Pulseway in the control panel uninstall feature and so I tried manually uninstalling files but that also did not work. I tried running the .msi installer again but an error came up saying that Pulseway is already installed but it still was not showing up. Please help me with this.
×
×
  • Create New...