-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate-Sysinternals.ps1
More file actions
63 lines (49 loc) · 1.81 KB
/
Update-Sysinternals.ps1
File metadata and controls
63 lines (49 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function Set-PathVariable {
param (
[string]$AddPath,
[string]$RemovePath
)
$regexPaths = @()
if ($PSBoundParameters.Keys -contains 'AddPath'){
$regexPaths += [regex]::Escape($AddPath)
}
if ($PSBoundParameters.Keys -contains 'RemovePath'){
$regexPaths += [regex]::Escape($RemovePath)
}
$arrPath = $env:Path -split ';'
foreach ($path in $regexPaths) {
$arrPath = $arrPath | Where-Object {$_ -notMatch "^$path\\?"}
}
$env:Path = ($arrPath + $addPath) -join ';'
[System.Environment]::SetEnvironmentVariable('Path', $env:Path, [System.EnvironmentVariableTarget]::Machine)
}
$SysIntPath = 'c:\SysInt'
$File = 'SysinternalsSuite.zip'
$URL = "https://download.sysinternals.com/files/$File"
$FilePath = "$SysIntPath\$File"
#Create Sysint directory if it doesn't exist
if (!(Test-Path $SysIntPath)){New-Item -Path $SysIntPath -ItemType "directory"}
#Add to Path
Set-PathVariable -AddPath $SysIntPath
#Delete Old SysinternalsSuite.zip if it exists
if (Test-Path $FilePath) {Remove-Item $FilePath}
#Download SysinternalsSuite.zip
#Import-Module BitsTransfer
try {
Start-BitsTransfer -Source $URL -Destination $FilePath
#unblock file
Unblock-File $FilePath
#remove old tools
Get-ChildItem $SysIntPath | where {$_.name -notmatch $File} |Remove-Item
}
catch {
Write-Output "Unable to download $URL"
}
#Unzip tools
try {
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($FilePath, $SysIntPath)
}
catch {
Write-Host "duplicatate file in SysinternalsSuite.zip.`nhttps://social.technet.microsoft.com/Forums/office/en-US/b11309ab-6e10-43f0-bc82-38ca230bfac7/two-dbgview-executables-why?forum=miscutils"
}