-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-SysinternalsSuite.ps1
183 lines (171 loc) · 8.49 KB
/
Get-SysinternalsSuite.ps1
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#requires -version 2.0
# Wintellect .NET Debugging Code
# (c) 2008 - 2009 by John Robbins\Wintellect - Do whatever you want to do with
# it as long as you give credit.
<#.SYNOPSIS
Gets all the wonderful Sysinternals tools
.DESCRIPTION
Downloads and extracts the Sysinternal tools to the directory you specify. This
script requires the excellent (and free) 7Z.EXE in the path to extract the
.ZIP file. You can get 7z at http://www.7-zip.org.
.PARAMETER Extract
The directory where you want to extract the Sysinternal tools.
.PARAMETER Save
The default is to download the SysinternalsSuite.zip file and remove it after
extracting the contents. If you want to keep the file, specify the save
directory with this parameter.
#>
param ( [string] $Extract = ($env:userprofile + "\utils\sysinternals" ) ,
[string] $Save )
function CreateDirectoryIfNeeded ( [string] $directory )
{
if ( ! ( Test-Path $directory -type "Container" ) )
{
New-Item -type directory -Path $directory > $null
}
}
##################################################################
# Main execution starts here.
$paramLog = @"
Param Extract = $Extract
Param Save = $Save
"@
Write-Debug $paramLog
[string]$sevenZName = "7Z.EXE"
# Verify I can find UNZIP.EXE in the path.
[string]$sevenZPath = $(Get-Command $sevenZName).Definition
if ( $sevenZPath.Length -eq 0 )
{
Write-Error "Unable to find $sevenZName in the path."
exit
}
# If the extract directory does not exist, create it.
CreateDirectoryIfNeeded ( $Extract )
# If there's a save directory set, us that otherwise, use the %TEMP% directory.
[Boolean]$deleteZipFile = $TRUE
[String]$downloadFile = ""
if ( $Save.Length -gt 0 )
{
CreateDirectoryIfNeeded ( $Save )
$downloadFile = $Save
$deleteZipFile = $FALSE
}
else
{
# Use the %TEMP% path for the user.
$downloadFile = $env:temp
}
# Build up the full location and filename.
$downloadFile = $(Get-item $downloadFile).FullName
$downloadFile = Join-Path -path $downloadFile -childpath "SysinternalsSuite.zip"
# Let the download begin!
Write-Output "Starting download of the Sysinternals Suite"
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile("http://download.sysinternals.com/Files/SysinternalsSuite.zip" ,
$downloadFile)
Write-Output "Sysinternals suite downloaded to $downloadFile"
# I don't like to see all the output from 7z unless there's a problem so I'll
# redirect to a temporary file and if there's any problems, I'll show it.
$temp7zOutput = [System.IO.Path]::GetTempFileName()
# Since the -o option to 7Z.EXE cannot have a space between it and the
# directory there's a bit of a problem. PowerShell does not expand the
# line -o$Extract if passed directly on the command line.
$outputOption = "-o$Extract"
Write-Output "Extracting files into $Extract"
&$sevenZPath x -y $outputOption $downloadFile > $temp7zOutput
if ( $LASTEXITCODE -ne 0 )
{
# There was a problem extracting.
Get-Content $temp7zOutput
# Don't delete the download file.
$deleteZipFile = $FALSE
Write-Error "Error extracting the .ZIP file"
Write-Error "The downloaded .ZIP file is at $downloadFile and will not be deleted."
}
# Delete the file that held the extraction output.
del $temp7zOutput
# Delete the downloaded .ZIP file if I'm supposed to.
if ( $deleteZipFile -eq $TRUE )
{
Remove-Item $downloadFile
}
# SIG # Begin signature block
# MIIOkQYJKoZIhvcNAQcCoIIOgjCCDn4CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQY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