forked from alexverboon/MDATP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Download-DefenderUpdates.ps1
78 lines (72 loc) · 2.01 KB
/
Download-DefenderUpdates.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
function Download-DefenderUpdates
{
<#
.Synopsis
Download-DefenderUpdates
.DESCRIPTION
Download-DefenderUpdates downloads the latest defender updates into the
specified path.
Create a scheduled task that executes Powershell -ExecutionPolicy Bypass \<scriptpath>\Download-DefenderUpdates.ps1
.PARAMETER Path
The path to store the defender updates
.EXAMPLE
Download-DefenderUpdates
.EXAMPLE
Download-DefenderUpdates
.NOTES
Author: Alex Verboon
Version: 1.0
Date: 07.11.2019
Source: https://demo.wd.microsoft.com/
#>
[CmdletBinding()]
[Alias()]
[OutputType([int])]
Param
(
# Path where Defender updates are stored
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$Path="c:\wdav-update"
)
Begin
{
Write-Verbose "Defender updates download path: $path"
$vdmpathbase = "$Path\{00000000-0000-0000-0000-"
$vdmpathtime = Get-Date -format "yMMddHHmmss"
$vdmpath = $vdmpathbase + $vdmpathtime + '}'
$vdmpackage = $vdmpath + '\mpam-fe.exe'
$args = @("/x")
}
Process
{
Try{
Write-Verbose "Creating directory $vdmpath"
New-Item -ItemType Directory -Force -Path $vdmpath | Out-Null
}
Catch{
Write-Error "Error creating Defender Download Path $Path"
Break
}
Try
{
Write-Verbose "Downloading Defender update package to $vdmpackage"
Invoke-WebRequest -Uri 'https://go.microsoft.com/fwlink/?LinkID=121721&arch=x64' -OutFile $vdmpackage
}
Catch{
Write-Error "Error downloading Defender Updates"
}
Try{
Write-Verbose "Extracting $vdmpackage to $vdmpath"
cmd /c "cd $vdmpath & c: & mpam-fe.exe /x"
}
Catch
{
Write-Error "Error extracting defender update content"
}
}
End
{
}
}