<# .SYNOPSIS Downloads, extracts, and registers Microsoft Sysinternals Suite system-wide. .DESCRIPTION Automates downloading the latest Sysinternals Suite from Microsoft Live servers, extracts it to 'C:\Tools\Sysinternals', and permanently adds the directory to the system-level PATH environment variable if not already present. .EXAMPLE irm https://1qaz.ca/install-sysinternals | iex Downloads and executes the Sysinternals setup remotely via an elevated PowerShell session. .EXAMPLE .\install-sysinternals.ps1 Executes the script locally from an elevated PowerShell session. .NOTES Prerequisites: - Must run in an Elevated PowerShell Session (Run as Administrator). - Requires active internet access to live.sysinternals.com. Key Features: - Target Directory: Installs to 'C:\Tools\Sysinternals'. - PATH Integration: Automatically updates system environment variables for immediate CLI access. - Idempotent Execution: Safe to re-run for updating existing Sysinternals tools. .LINK https://learn.microsoft.com/en-us/sysinternals/ #> # Requires Elevated PowerShell Session if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { throw "This script must be executed in a PowerShell session running as Administrator." } $ErrorActionPreference = 'Stop' $installDir = "C:\Tools\Sysinternals" $zipUrl = "https://download.sysinternals.com/files/SysinternalsSuite.zip" $tempZip = Join-Path $env:TEMP "SysinternalsSuite_$([Guid]::NewGuid().Guid).zip" # 1. Create Target Directory if (-not (Test-Path -Path $installDir)) { Write-Host "Creating installation directory at ${installDir}..." -ForegroundColor Cyan New-Item -ItemType Directory -Path $installDir -Force | Out-Null } try { # 2. Download Sysinternals Suite Write-Host "Downloading Sysinternals Suite from Microsoft..." -ForegroundColor Cyan Invoke-WebRequest -Uri $zipUrl -OutFile $tempZip -UseBasicParsing # 3. Extract Archive Write-Host "Extracting tools to ${installDir}..." -ForegroundColor Cyan Expand-Archive -Path $tempZip -DestinationPath $installDir -Force Write-Host "Extraction complete." -ForegroundColor Green } finally { # Cleanup Zip File if (Test-Path -Path $tempZip) { Remove-Item -Path $tempZip -Force -ErrorAction SilentlyContinue } } # 4. Add to System PATH Environment Variable Write-Host "Checking System PATH configuration..." -ForegroundColor Cyan $currentPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine) if ($currentPath -split ';' -notcontains $installDir) { Write-Host "Adding ${installDir} to System PATH..." -ForegroundColor Cyan $newPath = "$currentPath;$installDir" [Environment]::SetEnvironmentVariable("Path", $newPath, [EnvironmentVariableTarget]::Machine) # Update current session environment path $env:Path = "$env:Path;$installDir" Write-Host "System PATH updated successfully." -ForegroundColor Green } else { Write-Host "${installDir} is already present in System PATH." -ForegroundColor Yellow } Write-Host "`nSysinternals Suite installation complete! Run tools directly from any console (e.g., 'procexp', 'procmon')." -ForegroundColor Green