Last active
April 16, 2017 00:59
-
-
Save JPRuskin/1e8853d36000fbe399ac to your computer and use it in GitHub Desktop.
Updates all SysInternals tools contained within $localDirectory from live.sysinternals.com.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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