Quickly update Windows SysInternals executables

Discussion in 'Scripting' started by GodHand, Jul 2, 2019.

  1. GodHand

    GodHand MDL Addicted

    Jul 15, 2016
    534
    926
    30
    #1 GodHand, Jul 2, 2019
    Last edited: Aug 29, 2019
    This function will download the latest Windows SysInternals Suite, compare all files and replace any that have been updated. This is quicker than manually downloading the entire suite package and copying over all of its contents, and can be done in a single simple command.

    This can be added to a current PowerShell module or pasted directly into PowerShell or PowerShell ISE. Further examples are included within the function.

    Updated on 08-28-19 to use TLS 1.2 or above

    Code:
    Function Update-SysInternals
    {
    <#
        .SYNOPSIS
           Automatically updates any SysInternals Suite utility with its most recent file version.
     
       .DESCRIPTION
           Automatically updates any SysInternals Suite utility with its most recent file version.
     
       .PARAMETER SuitePath
           The directory path to the SysInternals Suite utilities.
     
       .EXAMPLE
           PS C:\> Update-SysInternals -SuitePath "C:\SysInternalsSuite"
           PS C:\> "C:\Tools and Utilities\SysInternals" | Update-SysInternals
    #>
        [CmdletBinding()]
        Param
        (
           [Parameter(Mandatory = $true,
                      Position = 0,
                      HelpMessage = 'The directory path to the SysInternals Suite utilities.')]
           [ValidateScript({ Test-Path -Path (Resolve-Path -Path $_) })]
           [string]$SuitePath
        )
     
        Begin
       {
           If (!(Test-Connection -ComputerName $Env:COMPUTERNAME -Quiet)) { Write-Warning "The update requires an active internet connection."; Return }
           $ProcessPath = Get-Process -Name ZoomIt*, Desktops*, procexp* -ErrorAction SilentlyContinue | Where-Object -Property Name -NotLike *64 | Select-Object -Property Path
           Get-Process -Name ZoomIt*, Desktops*, procexp* -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
           $ArchiveURL = "http://live.sysinternals.com/Files/SysinternalsSuite.zip"
           $ArchivePath = Join-Path -Path $Env:TEMP -ChildPath SysinternalsSuite.zip
       }
       Process
       {
           Write-Host "Beginning Update..." -NoNewline -ForegroundColor Cyan
           [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
           (New-Object System.Net.WebClient).DownloadFile($ArchiveURL, $ArchivePath)
           $Current = Get-ChildItem -Path $SuitePath -Force
           $Updated = Get-ChildItem -Path $SuitePath -Force
           Expand-Archive -LiteralPath $ArchivePath -DestinationPath $SuitePath -Force
           Compare-Object -ReferenceObject $Current -DifferenceObject $Updated | Select-Object -ExpandProperty InputObject | ForEach-Object -Process { Get-ChildItem -Path ($SuitePath + '\' + $($_)) -Force } | Select-Object -Property Name, CreationTime
           Write-Host "[Complete]" -ForegroundColor Cyan
       }
       End
       {
           If ($ProcessPath) { $ProcessPath | ForEach-Object -Process { Start-Process -FilePath $($_.Path) -ErrorAction SilentlyContinue } }
           Remove-Item -Path $ArchivePath -Force -ErrorAction SilentlyContinue
       }
    }
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...