DSCResources/xDSCVault_Download/xDSCVault_Download.psm1

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
function Get-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param
    (
        [parameter(Mandatory = $true)]
        [System.String]
        $Version
    )

    $returnValue = @{
        Version = $Version
        URI     = ("https://releases.hashicorp.com/vault/" + $version + "/vault_" + $version + "_windows_amd64.zip")
    }

    $returnValue
}


function Set-TargetResource
{
    [CmdletBinding()]
    param
    (
        [parameter(Mandatory = $true)]
        [System.String]
        $Version
    )

    #Write-Verbose "Use this cmdlet to deliver information about command processing."

    #Write-Debug "Use this cmdlet to write debug information while troubleshooting."

    #Include this line if the resource requires a system reboot.
    #$global:DSCMachineStatus = 1
    
    $GetResource = Get-TargetResource -Version $Version
    [Net.ServicePointManager]::SecurityProtocol = [System.Security.Authentication.SslProtocols] "tls, tls11, tls12"
    Invoke-WebRequest -Uri $GetResource.URI -OutFile ("C:\Windows\Temp\Vault_" + $Version + ".zip")
}


function Test-TargetResource
{
    [CmdletBinding()]
    [OutputType([System.Boolean])]
    param
    (
        [parameter(Mandatory = $true)]
        [System.String]
        $Version
    )

    if ((Test-Path -Path "C:\Windows\Temp\Vault_$Version.zip") -ne $true)
    {
        return $false       
    }
    else
    {
        return $true
    }
}


Export-ModuleMember -Function *-TargetResource