PowerShell – Yet another Sysinternals download script

Today I completed the Microsoft Virtual Academy Advanced Tools & Scripting with PowerShell 3.0 Jump Start course. If you haven’t looked at it yet, I realy recommend you do so, lots of good stuff there. So for the purpose of applying some of the stuff I’ve learned there regarding the use of -Whatif and -verbose messages i wrote the below script which downloads the sysinternals tools.


   Download Sysinternals Tools
   Download the Sysinternals tools from live.sysinternals.com to the local machine
    version 1.0
   Get-Sysinternals -Path C:\Data|sysinternals
   Get-Sysinternals.ps1 -Path C:\Data\Sysinternals -Whatif -verbose

           HelpMessage= 'The local download folder')]

    Write-Verbose "Starting Sysinternals Tool download"

    if ((Test-path -path $Directory) -eq $False)
        Write-Verbose "Creating Directory $Directory"
        if ($PScmdlet.ShouldProcess("Creating folder $Directory","",""))
        {New-Item -ItemType Directory -Path $Directory}

    $siuri = Invoke-WebRequest -Uri $url -EA SilentlyContinue
    if ($siuri.BaseResponse.StatusCode -eq "OK")
            $sfiles = $siuri.Links | Where-Object {$_.href -ne '/'} | Select-Object -ExpandProperty innerText
        Write-Verbose "Unable to reach $url"
        Exit 1

    ForEach ($st in  $sfiles)
        $downloadfile = $url+$st
        #Write-Verbose -Message "Downloading $downloadfile to $Directory\$st"
        if ($PScmdlet.ShouldProcess("Downloading now $downloadfile to $Directory\$st","",""))
            {Start-BitsTransfer -Description "SysinternalsDownload - $st" -Source $downloadfile -Destination "$Directory\$st"}

        Write-Verbose "Download complete"

Leave a Reply