Configurations/PowerCLI/pcli01-PowerCLI.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
55
56
57
58
59
60
61
62
63
# Configure PowerCLi on vEng
#
# Tested platform:
# Windows 2012 R2
# PowerShell v5 Production Preview
#

$tgtName = 'vEng.local.lab'
$pcliName = 'VMware-PowerCLI-6.3.0-3737840.exe'

$configName = $tgtName.Split('.')[0]

Configuration $configName
{
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node $AllNodes.NodeName
    {
        File DirectoryCopy
        {
            Ensure = "Present"
            Type = "File"
            Recurse = $true
            SourcePath = "\\Pull\Repository\PowerCLI\$($pcliName)"
            DestinationPath = "%windir%\Temp\$($pcliName)"    
        }

        Log AfterDirectoryCopy
        {
            Message = "PowerCLI installation file copied"
            DependsOn = "[File]DirectoryCopy"
        }
        
        Package Install-PowerCli
        {
            Name = "VMware vSphere PowerCLI"
            Path = "C:\Windows\Temp\$($pcliName)"
            Arguments = '/b"C:\Windows\Temp" /VADDLOCAL=ALL /S /V"/qn REBOOT=ReallySuppress"'
            ProductId = ''
            Ensure= "Present"
            DependsOn = "[File]DirectoryCopy"
        }

        Log AfterInstall
        {
            Message = "PowerCLI installed"
            DependsOn = "[Package]Install-PowerCLI"
        }
    }
}

$configData = @{
    AllNodes = @(
        @{
            NodeName = $configName
        }
    )
}

Invoke-Expression  "$($configName) -ConfigurationData `$configData -OutputPath '.\DSC'"

Start-DscConfiguration -ComputerName $configName -Wait -Verbose -Force -Path .\DSC