Jump to content
kavaa

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*

 

Share this post


Link to post
Share on other sites

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 

 

 

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


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 SpartanGolf6
      I use Pulseway to monitor my finicky Dell Inspiron 15 7000 Gaming Laptop and I noticed my laptop has thousands upon thousands of logs in Event Logs. I specifically need the 'Application Event Logs', 'Security' and 'System' event logs saved, ideally as a .CSV file. I don't know much PowerShell/Bash/VBScript, so I was hoping someone knows how to do this.
    • By Joe Savage
      Hi there,
      Just wondering if this is an option. I attempted to do the following with batch, but didn't work due to the %appdata% value resolving to somewhere in C:\Windows.
      mkdir %appdata%\Microsoft\Teams\Backgrounds\Uploads copy "\\SERVER\SHARE\Teams Backup Images\*.jpg" %appdata%\Microsoft\Teams\Backgrounds\Uploads /y  
      Any ideas?
      Cheers,
      Joe
    • By Joe Savage
      Hi there,
      This might be a bit of a long shot - but I have an end client who's interested in deploying custom Teams issues with Pulseway (as there aren't many users in-office for obvious reasons).
      I've attempted to deploy this by pushing a batch script, to copy the backgrounds from a shared location. The backgrounds folder in question is located in the user's roaming appdata (%appdata%\Microsoft\Teams\Backgrounds\Uploads). For this reason I wasn't able to use %username% correctly in my batch script, as the script is being run by some Pulseway service, rather than as the local user account.
       
      Please let me know if you've any ideas and have a great day.
       
      Cheers,
      Joe
    • By Sean Faria
      Hi,
      I am trying to install GCPW (Google Credential Provider for Windows).
      I am running into issue where with it:
      <# This script downloads Google Credential Provider for Windows from https://tools.google.com/dlpage/gcpw/, then installs and configures it. Windows administrator access is required to use the script. #> <# Set the following key to the domains you want to allow users to sign in from. For example: $domainsAllowedToLogin = "acme1.com,acme2.com" #> $domainsAllowedToLogin = "" Add-Type -AssemblyName System.Drawing Add-Type -AssemblyName PresentationFramework <# Check if one or more domains are set #> if ($domainsAllowedToLogin.Equals('')) { $msgResult = [System.Windows.MessageBox]::Show('The list of domains cannot be empty! Please edit this script.', 'GCPW', 'OK', 'Error') exit 5 } function Is-Admin() { $admin = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match 'S-1-5-32-544') return $admin } <# Check if the current user is an admin and exit if they aren't. #> if (-not (Is-Admin)) { $result = [System.Windows.MessageBox]::Show('Please run as administrator!', 'GCPW', 'OK', 'Error') exit 5 } <# Choose the GCPW file to download. 32-bit and 64-bit versions have different names #> $gcpwFileName = 'gcpwstandaloneenterprise.msi' if ([Environment]::Is64BitOperatingSystem) { $gcpwFileName = 'gcpwstandaloneenterprise64.msi' } <# Download the GCPW installer. #> $gcpwUrlPrefix = 'https://dl.google.com/credentialprovider/' $gcpwUri = $gcpwUrlPrefix + $gcpwFileName Write-Host 'Downloading GCPW from' $gcpwUri Invoke-WebRequest -Uri $gcpwUri -OutFile $gcpwFileName <# Run the GCPW installer and wait for the installation to finish #> $arguments = "/i "$gcpwFileName"" $installProcess = (Start-Process msiexec.exe -ArgumentList $arguments -PassThru -Wait) <# Check if installation was successful #> if ($installProcess.ExitCode -ne 0) { $result = [System.Windows.MessageBox]::Show('Installation failed!', 'GCPW', 'OK', 'Error') exit $installProcess.ExitCode } else { $result = [System.Windows.MessageBox]::Show('Installation completed successfully!', 'GCPW', 'OK', 'Info') } <# Set the required registry key with the allowed domains #> $registryPath = 'HKEY_LOCAL_MACHINE\Software\Google\GCPW' $name = 'domains_allowed_to_login' [microsoft.win32.registry]::SetValue($registryPath, $name, $domainsAllowedToLogin) $domains = Get-ItemPropertyValue HKLM:\Software\Google\GCPW -Name $name if ($domains -eq $domainsAllowedToLogin) { $msgResult = [System.Windows.MessageBox]::Show('Configuration completed successfully!', 'GCPW', 'OK', 'Info') } else { $msgResult = [System.Windows.MessageBox]::Show('Could not write to registry. Configuration was not completed.', 'GCPW', 'OK', 'Error') }
       
      I have tried the following:
      1. Run from batch file -- error "run as admin" but admin parameter was added
      2. Run from PowerShell --  error "leaves the script running forever"
      3. Pushed file to user and ran it (1) PowerShell -- error "needs run as admin" but admin parameter was added (2) batch -- error "script non-responsive"
    • By kappnet
      Hi,
      I am looking for a script that can trigger a 3rd party patch policy ad-hoc outside the policy schedule.
      It´s going to be used to start the installation process of software on newly registered machines in a "Computer registered" workflow.
      If there is anyone with another take on that I´m all ears.

      Best regards

      Mike

       
       
×
×
  • Create New...