Code/Get-SysinternalsSuite.ps1

#requires -version 5.0
###############################################################################
# WintellectPowerShell Module
# Copyright (c) 2010-2017 - John Robbins/Wintellect
#
# Do whatever you want with this module, but please do give credit.
###############################################################################

# Always make sure all variables are defined and all best practices are
# followed.
Set-StrictMode -version Latest

###############################################################################
# Public Cmdlets
###############################################################################
function Get-SysinternalsSuite
{
<#
.SYNOPSIS
Gets all the wonderful Sysinternals tools.
 
.DESCRIPTION
Downloads and extracts the Sysinternal tools to the directory you specify.
 
.PARAMETER ExtractTo
The directory where you want to extract the Sysinternal tools.
 
.PARAMETER Save
The default is to download the SysinternalsSuite.zip file and remove it after
extracting the contents. If you want to keep the file, specify the save directory
with this parameter.
 
.LINK
http://www.wintellect.com/devcenter/author/jrobbins
https://github.com/Wintellect/WintellectPowerShell
 
#>

    param ( 
        [Parameter(Mandatory=$true,
                   HelpMessage="Please specify the extract directory")]
        [Alias("Extract")]
        [string] $ExtractTo ,
        [Parameter(HelpMessage="Please specify the directory to expand into")]
        [string] $Save=""
    ) 
    
    New-Item -ItemType Directory -Path $ExtractTo -ErrorAction SilentlyContinue > $null

    [Boolean]$deleteZipFile = $TRUE
    [String]$downloadFile = ""
    if ( $Save.Length -gt 0 )
    { 
        New-Item -ItemType Directory -Path $Save -ErrorAction SilentlyContinue > $null
        $downloadFile = $Save
        $deleteZipFile = $FALSE
    }
    else
    { 
        # Use the %TEMP% path for the user.
        $downloadFile = $env:temp
    }
    
    # Build up the full location and filename.
    $downloadFile = $(Get-item -Path $downloadFile).FullName
    $downloadFile = Join-Path -path $downloadFile -childpath "SysinternalsSuite.zip" 

    # Let the download begin!
    Invoke-WebRequest -Uri "http://download.sysinternals.com/files/SysinternalsSuite.zip" -OutFile $downloadFile

    # Because the SysinternalsSuite.zip is quite large, I've seen very random instances where
    # the Expand-Archive fails because some anti-virus lock the file in exclusive mode.
    # I hate doing this but don't see any other way around the issue.
    Start-Sleep -Seconds 1

    # Now expand away.
    Expand-Archive -Path $downloadFile -DestinationPath $ExtractTo -Force
    
    # Strip off the NTFS stream marking the files as downloaded. We trust Mark. :)
    Unblock-File -Path $ExtractTo
    
    if ($deleteZipFile -eq $true)
    {
        Remove-Item -Path $downloadFile    
    }
}

# SIG # Begin signature block
# MIIaQwYJKoZIhvcNAQcCoIIaNDCCGjACAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUfuFoz1Q88y4dtvuUFICi9ZDo
# 1M6gghUyMIIEmTCCA4GgAwIBAgIPFojwOSVeY45pFDkH5jMLMA0GCSqGSIb3DQEB
# BQUAMIGVMQswCQYDVQQGEwJVUzELMAkGA1UECBMCVVQxFzAVBgNVBAcTDlNhbHQg
# TGFrZSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxITAfBgNV
# BAsTGGh0dHA6Ly93d3cudXNlcnRydXN0LmNvbTEdMBsGA1UEAxMUVVROLVVTRVJG
# aXJzdC1PYmplY3QwHhcNMTUxMjMxMDAwMDAwWhcNMTkwNzA5MTg0MDM2WjCBhDEL
# MAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UE
# BxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxKjAoBgNVBAMT
# IUNPTU9ETyBTSEEtMSBUaW1lIFN0YW1waW5nIFNpZ25lcjCCASIwDQYJKoZIhvcN
# AQEBBQADggEPADCCAQoCggEBAOnpPd/XNwjJHjiyUlNCbSLxscQGBGue/YJ0UEN9
# xqC7H075AnEmse9D2IOMSPznD5d6muuc3qajDjscRBh1jnilF2n+SRik4rtcTv6O
# KlR6UPDV9syR55l51955lNeWM/4Og74iv2MWLKPdKBuvPavql9LxvwQQ5z1IRf0f
# aGXBf1mZacAiMQxibqdcZ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