Get-SysInternals (script to update your tools)
For those who don’t know a while back MS started allowing direct access to the SysInternal tools via a WebDav share located here \\live.sysinternals.com\tools. While this did make access to SysInternal tools much eaiser, it still has issues with proxies so I wrote this script (it will be added to my BSonPosh module.)
NOTE: This is for V2 Only
Help from the script
.Synopsis
List or updates sysinternal files from the internet.Description
List or updates sysinternal files from the internet.Parameter Path
Where you want the files to download to..Parameter FileName
The FileName you want to download.Parameter All
Updates all the Files.Parameter Passthru
Returns a FileInfo Object for the downloaded file.Example
# To see a list of available files from Sysinternals
Get-SysInternals# To download a single file
Get-SysInternals -FileName pslist.exe# To download all the files available
Get-SysInternals -All# To download only files you already have
Get-ChildItem C:\tools | Get-SysInternals
The Code
Download it: Get-SysInternals.ps1
{
<#
.Synopsis
List or updates sysinternal files from the internet
.Description
List or updates sysinternal files from the internet
.Parameter Path
Where you want the files to download to.
.Parameter FileName
The FileName you want to download
.Parameter All
Updates all the Files
.Parameter Passthru
Returns a FileInfo Object for the downloaded file
.Example
# To see a list of available files from Sysinternals
Get-SysInternals
# To download a single file
Get-SysInternals -FileName pslist.exe
# To download all the files available
Get-SysInternals -All
# To download only files you already have
Get-ChildItem C:\tools | Get-SysInternals
.ReturnValue
Object
.Link
N/A
.Notes
NAME: Get-SysInternals
AUTHOR: YetiCentral\bshell
Website: www.bsonposh.com
LASTEDIT: 03/16/2009 18:25:15
#Requires -Version 2.0
#>
[cmdletbinding()]
Param(
[parameter()]
$Path,
[parameter(ValueFromPipeLine=$true)]
$FileName,
[parameter()]
[switch]$All,
[parameter()]
[switch]$Passthru
)
Begin
{
if(!$Path)
{
$ToolsPath = split-path (Get-command pslist.exe).Path -parent
if(!$ToolsPath)
{
$path = Read-Host "Enter Path: "
}
else
{
$path = $ToolsPath
}
}
Write-Verbose " Path: $Path"
Write-Verbose " FileName: $FileName"
write-verbose " ALL: $ALL"
$Cont = $true
}
Process
{
if($FileName)
{
Try
{
Write-Verbose " Downloading File [$FileName]"
$webclient.DownloadFile("http://live.sysinternals.com/$FileName","$path\$FileName")
Write-Verbose " ==> Downloaded [$FileName]"
if($passthru){Get-Item "$path\$FileName"}
}
catch
{
Write-Verbose " Failed to Download File [$FileName]"
}
$cont = $false
}
}
End
{
if($Cont)
{
# Get file content
$webclient = New-Object System.Net.WebClient
$HTML = $webclient.DownloadString("http://live.sysinternals.com/")
$links = $HTML -split ""
$Files = @()
# Building RegEx
$regex = "^.*y,\s(?.*)(AM|PM)"
$regex += "\s*(?\d*)\s+\"
$regex += "<a href="\`">(?.*)\"
# Creating an Object from the Links
switch -regex ($links)
{
$regex
{
$myobj = "" | Select FileName,Date,Length
$myobj.FileName += $matches.FileName
$myobj.Date = get-date $matches.Date
$myobj.Length = $matches.Length
$files += $myobj
}
}
if($All)
{
foreach($file in $files)
{
$FileName = $file.FileName
Try
{
Write-Verbose " Downloading File [$FileName] to [$Path]"
$webclient.DownloadFile("http://live.sysinternals.com/$FileName","$path\$FileName")
Write-Verbose " ==> Downloaded [$FileName]"
if($passthru){Get-Item "$path\$FileName"}
}
catch
{
Write-Verbose " Failed to Download File [$File]"
}
}
}
else
{
$files
}
}
}
}</a>
2 Responses to “Get-SysInternals (script to update your tools)”
Leave a Reply
You must be logged in to post a comment.


Hi,
Just a small typo at the top of the script (confusing HTML!).
The third line reads:
<#
It should read:
<#
Thanks Thomas… it is stupid code highlighter