Save-Dynamics365Resource.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
Import-Module $PSScriptRoot\DownloadAndUnpack-Dynamics365Resource.psm1 -DisableNameChecking
function Save-Dynamics365Resource
{
    [CmdletBinding()]
    param
    (
        [Parameter(Position=0)]
        [ArgumentCompleter(
            {
                $Dynamics365Resources | Get-Member -MemberType NoteProperty | % { $_.Name }
            }
        )]
        [ValidateScript(
            {
                $Dynamics365Resources.$_
            }
        )]
        [string]
        $Resource,
        [Parameter(Position=1)]
        [string]
        $TargetDirectory
    )
    if ( $resource )
    {
        $resourceUrl = $Dynamics365Resources.$resource.URL;
        if ( $TargetDirectory )
        {
            $directoryPath = $TargetDirectory;
        } else {
            $directoryName = $resource;
            $directoryPath = ".\$directoryName";
            Write-Debug "Directory Path: $directoryPath";
        }
        DownloadAndUnpack-Dynamics365Resource -ResourceUrl $resourceUrl -DirectoryPath $directoryPath -ExpectedFileChecksum $Dynamics365Resources.$resource.checksum;
    } else {
        Write-Debug "Downloading all URLs"
        if ( $TargetDirectory )
        {
            $Dynamics365Resources | Get-Member -MemberType NoteProperty | ForEach-Object {
                $resourceUrl = $Dynamics365Resources.( $_.Name ).URL;
                $directoryName = $_.Name;
                $directoryPath = "$TargetDirectory\$directoryName";
                DownloadAndUnpack-Dynamics365Resource -ResourceUrl $resourceUrl -DirectoryPath $directoryPath;
            }
        } else {
            $Dynamics365Resources | Get-Member -MemberType NoteProperty | ForEach-Object {
                $resourceUrl = $Dynamics365Resources.( $_.Name ).URL;
                $directoryName = $_.Name;
                $directoryPath = ".\$directoryName";
                Write-Output "directoryPath: $directoryPath"
                DownloadAndUnpack-Dynamics365Resource -ResourceUrl $resourceUrl -DirectoryPath $directoryPath;
            }
        }
    }
}