Examples/Sample_xRemoteFileUsingProxy.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
configuration Sample_xRemoteFile_DownloadFileUsingProxy
{
    param
    (
        [string[]] $nodeName = 'localhost',

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String] $destinationPath,

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String] $uri,

        [String] $userAgent,

        [Hashtable] $headers,

        [String] $proxy
    )

    Import-DscResource -Name MSFT_xRemoteFile -ModuleName xPSDesiredStateConfiguration

    Node $nodeName
    {
        xRemoteFile DownloadFile
        {
            DestinationPath = $destinationPath
            Uri             = $uri
            UserAgent       = $userAgent
            Headers         = $headers
            Proxy           = $proxy
        }
    }
}

<#
Sample use (parameter values need to be changed according to your scenario):
 
Sample_xRemoteFile_DownloadFileUsingProxy `
    -destinationPath "$env:SystemDrive\fileName.jpg" `
    -uri "http://www.contoso.com/image.jpg"
 
Sample_xRemoteFile_DownloadFileUsingProxy `
    -destinationPath "$env:SystemDrive\fileName.jpg" `
    -uri "http://www.contoso.com/image.jpg" `
    -userAgent [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer `
    -headers @{"Accept-Language" = "en-US"} `
    -proxy 'http://10.22.93.1'
#>