-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGet-Definitions.ps1
593 lines (503 loc) · 47.8 KB
/
Get-Definitions.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
<#
.SYNOPSIS
Download antimalware definition update files for Microsoft and McAfee
.DESCRIPTION
Based on: How to manually download the latest antimalware definition updates for
Microsoft Forefront Client Security, Microsoft Forefront Endpoint
Protection 2010 and Microsoft System Center 2012 Endpoint Protection
.EXAMPLE
powershell.exe -ExecutionPolicy Bypass -file "Get-Definitions.ps1"
.NOTES
Script name: Get-Definitions.ps1
Author: Richard Tracy
Version: 2.0.0
DateCreated: 07/22/2015
LastUpdate: 05/15/2018
.LINK
https://www.mcafee.com/apps/downloads/security-updates/security-updates.aspx
http://support.microsoft.com/kb/935934/en
.LOG
2.0.0 - May 15, 2019 - Added Get-ScriptPath function to support VScode and ISE
1.0.0 - July 15, 2015 - initial
#>
#==================================================
# FUNCTIONS
#==================================================
Function Test-IsISE {
# try...catch accounts for:
# Set-StrictMode -Version latest
try {
return $psISE -ne $null;
}
catch {
return $false;
}
}
Function Get-ScriptPath {
If (Test-Path -LiteralPath 'variable:HostInvocation') { $InvocationInfo = $HostInvocation } Else { $InvocationInfo = $MyInvocation }
# Makes debugging from ISE easier.
if ($PSScriptRoot -eq "")
{
if (Test-IsISE)
{
$psISE.CurrentFile.FullPath
#$root = Split-Path -Parent $psISE.CurrentFile.FullPath
}
else
{
$context = $psEditor.GetEditorContext()
$context.CurrentFile.Path
#$root = Split-Path -Parent $context.CurrentFile.Path
}
}
else
{
#$PSScriptRoot
$PSCommandPath
#$MyInvocation.MyCommand.Path
}
}
Function Format-ElapsedTime($ts) {
$elapsedTime = ""
if ( $ts.Minutes -gt 0 ){$elapsedTime = [string]::Format( "{0:00} min. {1:00}.{2:00} sec.", $ts.Minutes, $ts.Seconds, $ts.Milliseconds / 10 );}
else{$elapsedTime = [string]::Format( "{0:00}.{1:00} sec.", $ts.Seconds, $ts.Milliseconds / 10 );}
if ($ts.Hours -eq 0 -and $ts.Minutes -eq 0 -and $ts.Seconds -eq 0){$elapsedTime = [string]::Format("{0:00} ms.", $ts.Milliseconds);}
if ($ts.Milliseconds -eq 0){$elapsedTime = [string]::Format("{0} ms", $ts.TotalMilliseconds);}
return $elapsedTime
}
Function Format-DatePrefix{
[string]$LogTime = (Get-Date -Format 'HH:mm:ss.fff').ToString()
[string]$LogDate = (Get-Date -Format 'MM-dd-yyyy').ToString()
$CombinedDateTime = "$LogDate $LogTime"
return ($LogDate + " " + $LogTime)
}
Function Write-LogEntry{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Message,
[Parameter(Mandatory=$false,Position=2)]
[string]$Source = '',
[parameter(Mandatory=$false)]
[ValidateSet(0,1,2,3,4)]
[int16]$Severity,
[parameter(Mandatory=$false, HelpMessage="Name of the log file that the entry will written to.")]
[ValidateNotNullOrEmpty()]
[string]$OutputLogFile = $Global:LogFilePath,
[parameter(Mandatory=$false)]
[switch]$Outhost = $Global:OutToHost
)
## Get the name of this function
[string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
[string]$LogTime = (Get-Date -Format 'HH:mm:ss.fff').ToString()
[string]$LogDate = (Get-Date -Format 'MM-dd-yyyy').ToString()
[int32]$script:LogTimeZoneBias = [timezone]::CurrentTimeZone.GetUtcOffset([datetime]::Now).TotalMinutes
[string]$LogTimePlusBias = $LogTime + $script:LogTimeZoneBias
# Get the file name of the source script
Try {
If ($script:MyInvocation.Value.ScriptName) {
[string]$ScriptSource = Split-Path -Path $script:MyInvocation.Value.ScriptName -Leaf -ErrorAction 'Stop'
}
Else {
[string]$ScriptSource = Split-Path -Path $script:MyInvocation.MyCommand.Definition -Leaf -ErrorAction 'Stop'
}
}
Catch {
$ScriptSource = ''
}
If(!$Severity){$Severity = 1}
$LogFormat = "<![LOG[$Message]LOG]!>" + "<time=`"$LogTimePlusBias`" " + "date=`"$LogDate`" " + "component=`"$ScriptSource`" " + "context=`"$([Security.Principal.WindowsIdentity]::GetCurrent().Name)`" " + "type=`"$Severity`" " + "thread=`"$PID`" " + "file=`"$ScriptSource`">"
# Add value to log file
try {
Out-File -InputObject $LogFormat -Append -NoClobber -Encoding Default -FilePath $OutputLogFile -ErrorAction Stop
}
catch {
Write-Host ("[{0}] [{1}] :: Unable to append log entry to [{1}], error: {2}" -f $LogTimePlusBias,$ScriptSource,$OutputLogFile,$_.Exception.ErrorMessage) -ForegroundColor Red
}
If($Outhost){
If($Source){
$OutputMsg = ("[{0}] [{1}] :: {2}" -f $LogTimePlusBias,$Source,$Message)
}
Else{
$OutputMsg = ("[{0}] [{1}] :: {2}" -f $LogTimePlusBias,$ScriptSource,$Message)
}
Switch($Severity){
0 {Write-Host $OutputMsg -ForegroundColor Green}
1 {Write-Host $OutputMsg -ForegroundColor Gray}
2 {Write-Warning $OutputMsg}
3 {Write-Host $OutputMsg -ForegroundColor Red}
4 {If($Global:Verbose){Write-Verbose $OutputMsg}}
default {Write-Host $OutputMsg}
}
}
}
function Show-ProgressStatus
{
<#
.SYNOPSIS
Shows task sequence secondary progress of a specific step
.DESCRIPTION
Adds a second progress bar to the existing Task Sequence Progress UI.
This progress bar can be updated to allow for a real-time progress of
a specific task sequence sub-step.
The Step and Max Step parameters are calculated when passed. This allows
you to have a "max steps" of 400, and update the step parameter. 100%
would be achieved when step is 400 and max step is 400. The percentages
are calculated behind the scenes by the Com Object.
.PARAMETER Message
The message to display the progress
.PARAMETER Step
Integer indicating current step
.PARAMETER MaxStep
Integer indicating 100%. A number other than 100 can be used.
.INPUTS
- Message: String
- Step: Long
- MaxStep: Long
.OUTPUTS
None
.EXAMPLE
Set's "Custom Step 1" at 30 percent complete
Show-ProgressStatus -Message "Running Custom Step 1" -Step 100 -MaxStep 300
.EXAMPLE
Set's "Custom Step 1" at 50 percent complete
Show-ProgressStatus -Message "Running Custom Step 1" -Step 150 -MaxStep 300
.EXAMPLE
Set's "Custom Step 1" at 100 percent complete
Show-ProgressStatus -Message "Running Custom Step 1" -Step 300 -MaxStep 300
#>
param(
[Parameter(Mandatory=$true)]
[string]$Message,
[Parameter(Mandatory=$true)]
[int]$Step,
[Parameter(Mandatory=$true)]
[int]$MaxStep,
[string]$SubMessage,
[int]$IncrementSteps,
[switch]$Outhost
)
Begin{
If($SubMessage){
$StatusMessage = ("{0} [{1}]" -f $Message,$SubMessage)
}
Else{
$StatusMessage = $Message
}
}
Process
{
If($Script:tsenv){
$Script:TSProgressUi.ShowActionProgress(`
$Script:tsenv.Value("_SMSTSOrgName"),`
$Script:tsenv.Value("_SMSTSPackageName"),`
$Script:tsenv.Value("_SMSTSCustomProgressDialogMessage"),`
$Script:tsenv.Value("_SMSTSCurrentActionName"),`
[Convert]::ToUInt32($Script:tsenv.Value("_SMSTSNextInstructionPointer")),`
[Convert]::ToUInt32($Script:tsenv.Value("_SMSTSInstructionTableSize")),`
$StatusMessage,`
$Step,`
$Maxstep)
}
Else{
Write-Progress -Activity "$Message ($Step of $Maxstep)" -Status $StatusMessage -PercentComplete (($Step / $Maxstep) * 100) -id 1
}
}
End{
Write-LogEntry $Message -Outhost:$Outhost
}
}
Function Download-FileProgress{
param(
[Parameter(Mandatory=$false)]
[Alias("Title")]
[string]$Name,
[Parameter(Mandatory=$true,Position=1)]
[string]$Url,
[Parameter(Mandatory=$true,Position=2)]
[Alias("TargetDest")]
[string]$TargetFile
)
Begin{
## Get the name of this function
[string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
}
Process
{
$ChildURLPath = $($url.split('/') | Select -Last 1)
$uri = New-Object "System.Uri" "$url"
$request = [System.Net.HttpWebRequest]::Create($uri)
$request.set_Timeout(15000) #15 second timeout
$response = $request.GetResponse()
$totalLength = [System.Math]::Floor($response.get_ContentLength()/1024)
$responseStream = $response.GetResponseStream()
$targetStream = New-Object -TypeName System.IO.FileStream -ArgumentList $targetFile, Create
$buffer = new-object byte[] 10KB
$count = $responseStream.Read($buffer,0,$buffer.length)
$downloadedBytes = $count
If($Name){$Label = $Name}Else{$Label = $ChildURLPath}
while ($count -gt 0)
{
$targetStream.Write($buffer, 0, $count)
$count = $responseStream.Read($buffer,0,$buffer.length)
$downloadedBytes = $downloadedBytes + $count
#Write-Progress -activity "Downloading file '$($url.split('/') | Select -Last 1)'" -status "Downloaded ($([System.Math]::Floor($downloadedBytes/1024))K of $($totalLength)K): " -PercentComplete ((([System.Math]::Floor($downloadedBytes/1024)) / $totalLength) * 100)
Show-ProgressStatus -Message ("Downloading: {0} ($([System.Math]::Floor($downloadedBytes/1024))K of $($totalLength)K): " -f $Label) -Step ([System.Math]::Floor($downloadedBytes/1024)) -MaxStep $totalLength
}
Start-Sleep 3
$targetStream.Flush()
$targetStream.Close()
$targetStream.Dispose()
$responseStream.Dispose()
}
End{
#Write-Progress -activity "Finished downloading file '$($url.split('/') | Select -Last 1)'"
If($Name){$Label = $Name}Else{$Label = $ChildURLPath}
Show-ProgressStatus -Message ("Finished downloading file: {0}" -f $Label) -Step $totalLength -MaxStep $totalLength
}
}
##* ==============================
##* VARIABLES
##* ==============================
# Use function to get paths because Powershell ISE and other editors have differnt results
$scriptPath = Get-ScriptPath
[string]$scriptDirectory = Split-Path $scriptPath -Parent
[string]$scriptName = Split-Path $scriptPath -Leaf
[string]$scriptBaseName = [System.IO.Path]::GetFileNameWithoutExtension($scriptName)
#Create Paths
$DefinitionsPath = Join-Path -Path $scriptDirectory -ChildPath 'Definitions'
$LogPath = Join-Path -Path $scriptDirectory -ChildPath 'Logs'
$Global:Verbose = $false
If($PSBoundParameters.ContainsKey('Debug') -or $PSBoundParameters.ContainsKey('Verbose')){
$Global:Verbose = $PsBoundParameters.Get_Item('Verbose')
$VerbosePreference = 'Continue'
Write-Verbose ("[{0}] [{1}] :: VERBOSE IS ENABLED." -f (Format-DatePrefix),$scriptName)
}
Else{
$VerbosePreference = 'SilentlyContinue'
}
#build log name
[string]$FileName = $scriptBaseName +'.log'
#build global log fullpath
$Global:LogFilePath = Join-Path $LogPath -ChildPath $FileName
Write-Host "logging to file: $LogFilePath" -ForegroundColor Cyan
# BUILD FOLDER STRUCTURE
#=======================================================
New-Item $SoftwarePath -type directory -ErrorAction SilentlyContinue | Out-Null
New-Item $RelativeLogPath -type directory -ErrorAction SilentlyContinue | Out-Null
#==================================================
# MAIN - DOWNLOAD 3RD PARTY SOFTWARE
#==================================================
## Load the System.Web DLL so that we can decode URLs
Add-Type -Assembly System.Web
$wc = New-Object System.Net.WebClient
# Proxy-Settings
#$wc.Proxy = [System.Net.WebRequest]::DefaultWebProxy
#$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
#Get-Process "firefox" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
#Get-Process "iexplore" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
#Get-Process "Openwith" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
# Microsoft Security Essentials - X64 DOWNLOAD
#==================================================
Function Get-MSEDefinition {
param(
[parameter(Mandatory=$true)]
[string]$RootPath,
[parameter(Mandatory=$false)]
[ValidateSet('Windows 7 (x86)', 'Windows 7 (x64)', 'Windows 7 (Both)','Windows 10 (x86)','Windows 10 (x64)','Windows 10 (Both)','All (x86)','All (x64)','All')]
[string]$OSType = 'All'
)
Begin{
## Get the name of this function
[string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
}
Process
{
$Product = "Microsoft Security Essentials"
[System.Uri]$DownloadURL = "http://go.microsoft.com"
## -------- BUILD DOWNLOAD LINKS ----------
#get the appropiate url based on architecture and OS
switch($OSType){
'Windows 7 (x86)' {$ntOS="6.1";$DownloadLinks = "$DownloadURL/fwlink/?LinkID=121721&clcid=0x409&arch=x86&eng=0.0.0.0&avdelta=0.0.0.0&asdelta=0.0.0.0&prod=925A3ACA-C353-458A-AC8D-A7E5EB378092"}
'Windows 7 (x64)' {$ntOS="6.1";$DownloadLinks = "$DownloadURL/fwlink/?LinkID=121721&clcid=0x409&arch=x64&eng=0.0.0.0&avdelta=0.0.0.0&asdelta=0.0.0.0&prod=925A3ACA-C353-458A-AC8D-A7E5EB378092"}
'Windows 7 (Both)' {$ntOS="6.1";$DownloadLinks = "$DownloadURL/fwlink/?LinkID=121721&clcid=0x409&arch=x86&eng=0.0.0.0&avdelta=0.0.0.0&asdelta=0.0.0.0&prod=925A3ACA-C353-458A-AC8D-A7E5EB378092",
"$DownloadURL/fwlink/?LinkID=121721&clcid=0x409&arch=x64&eng=0.0.0.0&avdelta=0.0.0.0&asdelta=0.0.0.0&prod=925A3ACA-C353-458A-AC8D-A7E5EB378092"}
'Windows 10 (x86)' {$ntOS="10.0";$DownloadLinks = "$DownloadURL/fwlink/?LinkID=121721&arch=x86"}
'Windows 10 (x64)' {$ntOS="10.0";$DownloadLinks = "$DownloadURL/fwlink/?LinkID=121721&arch=x64"}
'Windows 10 (Both)' {$ntOS="10.0";$DownloadLinks = "$DownloadURL/fwlink/?LinkID=121721&arch=x86",
"$DownloadURL/fwlink/?LinkID=121721&arch=x64"}
'All' {$ntOS="All";$DownloadLinks = "$DownloadURL/fwlink/?LinkID=121721&clcid=0x409&arch=x86&eng=0.0.0.0&avdelta=0.0.0.0&asdelta=0.0.0.0&prod=925A3ACA-C353-458A-AC8D-A7E5EB378092",
"$DownloadURL/fwlink/?LinkID=121721&clcid=0x409&arch=x64&eng=0.0.0.0&avdelta=0.0.0.0&asdelta=0.0.0.0&prod=925A3ACA-C353-458A-AC8D-A7E5EB378092",
"$DownloadURL/fwlink/?LinkID=121721&arch=x86",
"$DownloadURL/fwlink/?LinkID=121721&arch=x64"
}
'All (x64)' {$ntOS="All";$DownloadLinks = "$DownloadURL/fwlink/?LinkID=121721&clcid=0x409&arch=x64&eng=0.0.0.0&avdelta=0.0.0.0&asdelta=0.0.0.0&prod=925A3ACA-C353-458A-AC8D-A7E5EB378092",
"$DownloadURL/fwlink/?LinkID=121721&arch=x64"
}
'All (x86)' {$ntOS="All";$DownloadLinks = "$DownloadURL/fwlink/?LinkID=121721&clcid=0x409&arch=x86&eng=0.0.0.0&avdelta=0.0.0.0&asdelta=0.0.0.0&prod=925A3ACA-C353-458A-AC8D-A7E5EB378092",
"$DownloadURL/fwlink/?LinkID=121721&arch=x86"
}
}
Write-LogEntry ("Parsing site: {0} for {1} {2} full definition files" -f $DownloadURL.AbsoluteUri,$OSType,$DefName) -Outhost
## -------- BUILD FOLDERS ----------
$DestinationPath = Join-Path -Path $RootPath -ChildPath $FolderPath
If( !(Test-Path $DestinationPath)){
New-Item $DestinationPath -type directory -ErrorAction SilentlyContinue | Out-Null
}
## -------- DOWNLOAD SOFTWARE ----------
Foreach ($link in $DownloadLinks){
#build Download link from Root URL (if Needed)
$DownloadLink = $link
Write-LogEntry ("Validating Download Link: [{0}]..." -f $DownloadLink) -Severity 1 -Source ${CmdletName} -Outhost
If($DownloadLink -match "prod=925A3ACA-C353-458A-AC8D-A7E5EB378092"){
If($DownloadLink -match "arch=x64"){
$subpath = Join-Path -Path $DestinationPath -ChildPath "Win7\x64"
$ArchLabel = '(64-bit)'
}
Else{
$subpath = Join-Path -Path $DestinationPath -ChildPath "Win7\x86"
$ArchLabel = '(32-bit)'
}
}
Else{
If($DownloadLink -match "arch=x64"){
$subpath = Join-Path -Path $DestinationPath -ChildPath "Win10\x64"
$ArchLabel = '(64-bit)'
}
Else{
$subpath = Join-Path -Path $DestinationPath -ChildPath "Win10\x86"
$ArchLabel = '(32-bit)'
}
}
New-Item -Path $subpath -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
$destination = $DestinationPath + "\" + $Version + "\" + $Filename
#find what arch the file is based on the integer 64
$ExtensionType = [System.IO.Path]::GetExtension($fileName)
Try{
Write-LogEntry ("Attempting to download: [{0}]." -f $Filename) -Severity 1 -Source ${CmdletName} -Outhost
Download-FileProgress -Name ("{0}" -f $Filename) -Url $DownloadLink -TargetDest $destination
#$wc.DownloadFile($link, $destination)
Write-LogEntry ("Succesfully downloaded: {0} {1} to [{2}]" -f $Product,$ArchLabel,$destination) -Severity 0 -Source ${CmdletName} -Outhost
$downloaded=$True
}
Catch {
Write-LogEntry ("Failed downloading: {0} to [{1}]: {2}" -f $Product,$destination,$_.Exception) -Severity 3 -Source ${CmdletName} -Outhost
$downloaded=$False
}
}
}
}
Function Get-NISDefinition {
param(
[parameter(Mandatory=$true)]
[string]$RootPath,
[parameter(Mandatory=$false)]
[string]$FolderPath = "NIS",
[parameter(Mandatory=$false)]
[ValidateSet('x86','x64','Both')]
[string]$Arch = 'Both'
)
Begin{
## Get the name of this function
[string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
}
Process
{
$DefName = "Network-based exploit"
[System.Uri]$DownloadURL = "http://go.microsoft.com"
## -------- BUILD DOWNLOAD LINKS ----------
#get the appropiate url based on architecture and OS
switch($Arch){
'x86' {$DownloadLinks = "$DownloadURL/fwlink/?LinkID=187316&arch=x86&nri=true"}
'x64' {$DownloadLinks = "$DownloadURL/fwlink/?LinkID=187316&arch=x64&nri=true"}
'Both' {$DownloadLinks = "$DownloadURL/fwlink/?LinkID=187316&arch=x86&nri=true",
"$DownloadURL/fwlink/?LinkID=187316&arch=x64&nri=true"}
}
Write-LogEntry ("Parsing site: {0} for {1} {2} full definition files" -f $DownloadURL.AbsoluteUri,$OSType,$DefName) -Outhost
## -------- BUILD FOLDERS ----------
$DestinationPath = Join-Path -Path $RootPath -ChildPath $FolderPath
If( !(Test-Path $DestinationPath)){
New-Item $DestinationPath -type directory -ErrorAction SilentlyContinue | Out-Null
}
## -------- DOWNLOAD SOFTWARE ----------
Foreach ($link in $DownloadLinks){
#build Download link from Root URL (if Needed)
$DownloadLink = $link
Write-LogEntry ("Validating Download Link: [{0}]..." -f $DownloadLink) -Severity 1 -Source ${CmdletName} -Outhost
$Filename = 'nis_full.exe'
If($DownloadLink -match "arch=x64"){
$subpath = Join-Path -Path $DestinationPath -ChildPath "$FolderPath\x64"
$ArchLabel = '64-bit'
}
Else{
$subpath = Join-Path -Path $DestinationPath -ChildPath "$FolderPath\x86"
$ArchLabel = '32-bit'
}
New-Item -Path $subpath -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
$destination = $DestinationPath + "\" + $Version + "\" + $Filename
Try{
Write-LogEntry ("Attempting to download: [{0}]." -f $Filename) -Severity 1 -Source ${CmdletName} -Outhost
Download-FileProgress -Name ("{0}" -f $Filename) -Url $DownloadLink -TargetDest $destination
#$wc.DownloadFile($link, $destination)
Write-LogEntry ("Succesfully downloaded: {0} {1} to [{2}]" -f $Product,$ArchLabel,$destination) -Severity 0 -Source ${CmdletName} -Outhost
$downloaded=$True
}
Catch {
Write-LogEntry ("Failed downloading: {0} to [{1}]: {2}" -f $Product,$destination,$_.Exception) -Severity 3 -Source ${CmdletName} -Outhost
$downloaded=$False
}
}
}
}
# McAfee DAT V2 Virus Definition - DOWNLOAD
#==================================================
Function Get-DATDefinition {
param(
[parameter(Mandatory=$true)]
[string]$RootPath,
[parameter(Mandatory=$false)]
[string]$FolderPath = "McAfee",
[parameter(Mandatory=$false)]
[ValidateSet('x86','x64','Both')]
[string]$Arch = 'Both'
)
Begin{
## Get the name of this function
[string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
}
Process
{
$DefName = "McAfee DAT"
$SourceURL = Invoke-WebRequest "http://update.nai.com/products/commonupdater/gdeltaavv.ini"
## -------- GET VERSION ----------
[array]$A=$SourceURL -split "`r`n"
$CurrentVersion=$A[3].Split('=')[1]
## -------- BUILD DOWNLOAD LINKS ----------
[System.Uri]$DownloadURL="http://update.nai.com/products/datfiles/4.x/nai/$($CurrentVersion)xdat.exe"
#$datfile = (invoke-webrequest $DownloadURL).Content.RawContent
## -------- BUILD FOLDERS ----------
$DestinationPath = Join-Path -Path $RootPath -ChildPath $FolderPath
If( !(Test-Path $DestinationPath)){
New-Item $DestinationPath -type directory -ErrorAction SilentlyContinue | Out-Null
}
## -------- DOWNLOAD SOFTWARE ----------
Write-LogEntry ("Validating Download Link: [{0}]..." -f $DownloadURL.AbsoluteUri) -Severity 1 -Source ${CmdletName} -Outhost
$filename = $($CurrentVersion) + "xdat.exe"
$destination = $DestinationPath + "\" + $filename
If (Test-Path "$destination" -ErrorAction SilentlyContinue){
$LogComment = $($CurrentVersion) + "xdat.exe is already downloaded"
Write-LogEntry $LogComment -Source ${CmdletName} -Outhost
} Else {
Try{
Write-LogEntry ("Attempting to download: [{0}]." -f $Filename) -Severity 1 -Source ${CmdletName} -Outhost
Download-FileProgress -Name ("{0}" -f $Filename) -Url $DownloadLink -TargetDest $destination
#$wc.DownloadFile($link, $destination)
Write-LogEntry ("Succesfully downloaded: {0} to [{1}]" -f $Product,$destination) -Severity 0 -Source ${CmdletName} -Outhost
}
Catch {
Write-LogEntry ("Failed downloading: {0} to [{1}]: {2}" -f $Product,$destination,$_.Exception) -Severity 3 -Source ${CmdletName} -Outhost
}
}
}
}