Examples/Sample_InstallExeCredsRegistry_xPackage.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<#
Simple package that installs an .exe using credentials to access the installer and specifying RunAs Credentials.
This sample also uses custom registry data to discover the package.
 
#>

param
(
    [String]$OutputPath = ".",

    [parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [String] $Package,

    [parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [String] $Source,

    [parameter(Mandatory = $true)]
    [ValidateNotNull()]
    [String] $ProductId,
 
    [boolean] $CreateCheckRegValue = $false,

    [parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [String] $InstalledCheckRegKey,

    [parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [String] $InstalledCheckRegValueName,

    [parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [String] $InstalledCheckRegValueData,

    [parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [PSCredential] $Credential,

    [parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [PSCredential] $RunAsCredential,

    [parameter(Mandatory = $true)]
    [ValidateNotNull()]
    [PSCredential] $Arguments
)

Configuration Sample
{
    Import-DscResource -Module xPSDesiredStateConfiguration

    xPackage t1
    {
        Ensure="Present"
        Name = $Package
        Path = $Source
        Arguments = $Arguments
        RunAsCredential = $RunAsCredential
        Credential = $Credential
        ProductId = $ProductId
        CreateCheckRegValue = $CreateCheckRegValue
        InstalledCheckRegKey = $InstalledCheckRegKey
        InstalledCheckRegValueName = $InstalledCheckRegValueName
        InstalledCheckRegValueData = $InstalledCheckRegValueData
    }
}

$Global:AllNodes=
@{
    AllNodes = @(     
                    @{
                        NodeName = "localhost";
                        RecurseValue = $true;
                     };                                                                                     
                );    
}

<#
Sample use (parameter values need to be changed according to your scenario):
The reg key and value is created by xPacakage.
 
# Create the MOF file using the configuration data
Sample -OutputPath $OutputPath -ConfigurationData $Global:AllNodes -Package "Package Name" -Source "\\software\installer.exe" `
    -InstalledCheckRegKey "SOFTWARE\Microsoft\DevDiv\winexpress\Servicing\12.0\coremsi" `
    -InstalledCheckRegValueName "Install" -InstalledCheckRegValueData "1" `
    -CreateCheckRegValue $true
    -Credential $Credential -RunAsCredential $RunAsCredential `
    -Arguments "/q" -ProductId ""
 
#>