Examples/Sample_xWaitForItem.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
$machineNames = 'ServerA', 'ServerB'

configuration TestWaitForItem
{
param
(
    [string[]]$ComputerName
)
    Import-DscResource -ModuleName xDscHelper
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    node $ComputerName
    {
        <# Wait for a file to reach a specific length. In this case we are waiting for someone to copy
            the correct version of our sshd config
        #>

        xWaitForItem aFile
        {
            Path = 'C:\openssh\sshd.config'
            Type = 'File'
            Length = 12345
        }

        Service openSsh
        {
            Name = 'sshd'
            State = 'Running'
            StartupType = 'Automatic'
            Path = 'C:\openssh\sshd.exe'
            DependsOn = '[xWaitForItem]aFile'
        }

        # Now we wait for e.g. a DFS replicated folder to fully replicate with a broader retry count/interval
        xWaitForItem aFolder
        {
            Path = 'C:\SomeDfsTarget'
            Type = 'Directory'
            MinimumChildItemCount = 300
            RetryCount = 10
            RetryInterval = 60
        }

        <#SomeCompositeResource mySuperResource
        {
            SomeParam1 = 'Value1'
            DependsOn = '[xWaitForItem]aFolder'
        }#>

    }
}

TestWaitForItem -ComputerName $machineNames

Start-DscConfiguration -Verbose -Wait -Force -Path .\TestWaitForItem