Skip to content

Instantly share code, notes, and snippets.

@JPRuskin
Last active April 16, 2017 00:59
Show Gist options
  • Save JPRuskin/1e8853d36000fbe399ac to your computer and use it in GitHub Desktop.
Save JPRuskin/1e8853d36000fbe399ac to your computer and use it in GitHub Desktop.
Updates all SysInternals tools contained within $localDirectory from live.sysinternals.com.
function Get-SysInternalsTools {
[CmdletBinding(DefaultParameterSetName='Update')]
param(
[Parameter(Mandatory)]
$localDirectory,
[Parameter(ParameterSetName='Download')]
[Switch]$DownloadAll
)
begin {
$localTools = Get-ChildItem $localDirectory -Filter *.exe
$onlineTools = Get-ChildItem '\\live.sysinternals.com\tools' -Filter *.exe
}
process {
switch ($PSCmdlet.ParameterSetName) {
'Update' {
foreach ($tool in $localTools) {
if ($tool.LastWriteTime -lt ($online = $onlineTools | ?{$_.Name -eq $tool.Name}).LastWriteTime) {
Write-Verbose "[$($tool.Name)] requires updating..."
try {
Invoke-WebRequest -Uri $online.FullName -OutFile $tool.FullName -ErrorAction Stop
}
catch {
Write-Warning "$($tool.Name) failed to update."
}
}
}
}
'Download' {
foreach ($tool in $onlineTools) {
Copy-Item -Path $tool.FullName -Destination $localDirectory -Force
}
}
}
}
}
if ($MyInvocation.InvocationName -NE '.') {Update-SysInternalsTools -localDirectory 'C:\Users\James\Utilities\Portable Useful\sysinternals'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment