Examples/Test_Sample_xArchive_CompressArchive.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

$zipFilePath = "$pwd\Target.zip"

del "$pwd\Sample-1.txt" -Force -Recurse -ErrorAction SilentlyContinue
del "$pwd\Sample-2.txt" -Force -Recurse -ErrorAction SilentlyContinue
del "$pwd\Sample-3.txt" -Force -Recurse -ErrorAction SilentlyContinue
del "$pwd\SourceDir-1" -Force -Recurse -ErrorAction SilentlyContinue
del "$pwd\SourceDir-2" -Force -Recurse -ErrorAction SilentlyContinue

"Some Test Data - 1" > "$pwd\Sample-1.txt"
"Some Test Data - 2" > "$pwd\Sample-2.txt"
"Some Test Data - 3" > "$pwd\Sample-3.txt"

New-Item $pwd\SourceDir-1 -Type Directory | Out-Null
New-Item $pwd\SourceDir-1\Sample-1.txt -Type File | Out-Null
New-Item $pwd\SourceDir-1\Sample-2.txt -Type File | Out-Null

New-Item $pwd\SourceDir-2 -Type Directory | Out-Null
New-Item $pwd\SourceDir-2\Sample-1.txt -Type File | Out-Null
New-Item $pwd\SourceDir-2\Sample-2.txt -Type File | Out-Null

$sourceFilePath = @("$pwd\Sample-1.txt", "$pwd\Sample-2.txt", "$pwd\Sample-3.txt","$pwd\SourceDir-1", "$pwd\SourceDir-2")


Configuration Sample_xArchive_CompressArchive
{
    Import-DscResource -ModuleName xPSDesiredStateConfiguration
    Node localhost
    {
        xArchive SampleCompressArchive
        {
            Path = $sourceFilePath
            Destination = $zipFilePath
            CompressionLevel = "Optimal"
            DestinationType="File"
            MatchSource=$true
        }
    }
}

Sample_xArchive_CompressArchive