forked from dsccommunity/xPSDesiredStateConfiguration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxRemoteFile_DownloadFileWithChecksumConfig.ps1
125 lines (102 loc) · 3.99 KB
/
xRemoteFile_DownloadFileWithChecksumConfig.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
<#PSScriptInfo
.VERSION 1.0.1
.GUID 21b028d8-f319-4430-9b35-ae1bf1b7075a
.AUTHOR Microsoft Corporation
.COMPANYNAME Microsoft Corporation
.COPYRIGHT
.TAGS DSCConfiguration
.LICENSEURI https://github.com/dsccommunity/xPSDesiredStateConfiguration/blob/main/LICENSE
.PROJECTURI https://github.com/dsccommunity/xPSDesiredStateConfiguration
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES First version.
.PRIVATEDATA 2016-Datacenter,2016-Datacenter-Server-Core
#>
#Requires -module 'xPSDesiredStateConfiguration'
<#
.SYNOPSIS
Configuration that downloads a file.
.DESCRIPTION
Configuration that downloads a file.
.PARAMETER NodeName
The names of one or more nodes to compile a configuration for.
Defaults to 'localhost'.
.PARAMETER DestinationPath
The path where the remote file should be downloaded
.PARAMETER Uri
The URI of the file which should be downloaded. It must be a HTTP, HTTPS
or FILE resource.
.PARAMETER UserAgent
The user agent string for the web request.
.PARAMETER Headers
The headers of the web request.
.PARAMETER Checksum
Specifies the expected checksum value of downloaded file.
.PARAMETER ChecksumType
The algorithm used to calculate the checksum of the file.
.EXAMPLE
xRemoteFile_DownloadFileWithChecksumConfig -DestinationPath "$env:SystemDrive\fileName.jpg" -Uri 'http://www.contoso.com/image.jpg' -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer -Headers @{'Accept-Language' = 'en-US'} -ChecksumType MD5 -Checksum '31C1D431BBEB65E66113A8EBB06630DC'
Compiles a configuration that downloads the file 'http://www.contoso.com/image.jpg'
to the local file "$env:SystemDrive\fileName.jpg" and verifies the file against specified checksum.
.EXAMPLE
$configurationParameters = @{
DestinationPath = "$env:SystemDrive\fileName.jpg"
Uri = 'http://www.contoso.com/image.jpg'
UserAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer
Headers = @{
'Accept-Language' = 'en-US'
}
ChecksumType = 'MD5'
Checksum = '31C1D431BBEB65E66113A8EBB06630DC'
}
Start-AzureRmAutomationDscCompilationJob -ResourceGroupName '<resource-group>' -AutomationAccountName '<automation-account>' -ConfigurationName 'xRemoteFile_DownloadFileWithChecksumConfig' -Parameters $configurationParameters
Compiles a configuration in Azure Automation that downloads the file
'http://www.contoso.com/image.jpg' to the local file
"$env:SystemDrive\fileName.jpg" and verifies the file against specified checksum..
Replace the <resource-group> and <automation-account> with correct values.
#>
Configuration xRemoteFile_DownloadFileWithChecksumConfig
{
param
(
[Parameter()]
[System.String[]]
$NodeName = 'localhost',
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$DestinationPath,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Uri,
[Parameter()]
[System.String]
$UserAgent,
[Parameter()]
[System.Collections.Hashtable]
$Headers,
[Parameter()]
[System.String]
[ValidateSet('None', 'SHA1', 'SHA256', 'SHA384', 'SHA512', 'MACTripleDES', 'MD5', 'RIPEMD160')]
$ChecksumType = 'None',
[Parameter()]
[System.String]
$Checksum
)
Import-DscResource -ModuleName 'xPSDesiredStateConfiguration'
Node $nodeName
{
xRemoteFile 'DownloadFileWithChecksum'
{
DestinationPath = $DestinationPath
Uri = $Uri
UserAgent = $UserAgent
Headers = $Headers
ChecksumType = $ChecksumType
Checksum = $checksum
}
}
}