-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeployButton.ps1
186 lines (170 loc) · 7.52 KB
/
deployButton.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
[CmdletBinding()]
param
(
[parameter()]
[string]
$WorkspacePath = "C:\dscpush-master",
[parameter()]
[switch]
$DeployInfrastructure = $true,
[parameter()]
[string]
$VhdPath = "C:\VirtualHardDisks\win2016core.vhdx",
[parameter()]
[ipaddress]
$HostIpAddress = "192.0.0.247",
[parameter()]
[string]
$VSwitchName = "DSC-vSwitch1",
[parameter()]
[pscredential]
$DeploymentCredential = (New-Object System.Management.Automation.PSCredential ("administrator", (ConvertTo-SecureString "P@ssw0rd123" -AsPlainText -Force))),
[parameter()]
[string]
$NodeDefinitionFilePath = "$WorkspacePath\DSCPushSetup\DefinitionStore\NodeDefinition.ps1"
)
#region vars
#global vars
$targetLCMSettings = @{
ConfigurationModeFrequencyMins = 15
RebootNodeIfNeeded = $True
ConfigurationMode = "ApplyAndAutoCorrect"
ActionAfterReboot = "ContinueConfiguration"
RefreshMode = "Push"
AllowModuleOverwrite = $true
DebugMode = "None"
}
#shared vars
$dscPushModulePath = "$WorkspacePath\Modules\DSCPush"
$partialCatalogPath = "$WorkspacePath\DSCPushSetup\Settings\PartialCatalog.json"
#default vars
$PartialDirectoryPath = "$WorkspacePath\partials"
$contentStoreRootPath = "$WorkspacePath\ContentStore"
$ContentStoreDestPath = "C:\ContentStore"
$contentStoreModulePath = "$WorkspacePath\modules"
$DscResourcesPath = "$WorkspacePath\resources"
$partialSecretsPath = "$WorkspacePath\DSCPushSetup\Settings\PartialSecrets.json"
$StoredSecretsPath = "$WorkspacePath\DSCPushSetup\Settings\StoredSecrets.json"
$SecretsKeyPath = "$WorkspacePath\DSCPushSetup\Settings\SecretsKey.json"
$partialDependenciesFilePath = "$WorkspacePath\DSCPushSetup\Settings\PartialDependencies.json"
$partialSecretsPath = "$WorkspacePath\DSCPushSetup\Settings\PartialSecrets.json"
$mofOutputPath = "$WorkspacePath\DSCPushSetup\Settings\mofStore"
#Mof encryption vars
$mofEncryptionSettings = @{
EnableTargetMofEncryption = $false
TargetCertDirName = "Certificates"
MofEncryptionCertThumbprint = "C3CD32F10653BB2C9F795520583A9A1EF0C7D7DC"
MofEncryptionCertPath = "$WorkspacePath\Certificates\RpsDscEncryption.cer"
MofEncryptionPKPath = "$WorkspacePath\Certificates\RpsDscEncryption.pfx"
MofEncryptionPKPassword = $DeploymentCredential.Password
}
#endregion
#region import module
Get-Module DscPush -ErrorAction SilentlyContinue | Remove-Module
Import-Module -FullyQualifiedName $dSCPushModulePath -ErrorAction Stop
#endregion
#region Init - first step in publishing configs is to initialize your workspace
<#These settings will:
Generate a new partial catalog (required for first deployments and after any change to partials or partial path
Generate secrets for all pscredential Partial Configuration parameters (POPUPS WILL APPEAR!)
#>
$initDeploymentSettings = @{
GeneratePartialCatalog = $true
GenerateSecrets = $true
SeedDscResources = $true
DscResourcesPath = $DscResourcesPath
PartialCatalogPath = $partialCatalogPath
PartialDirectoryPath = $PartialDirectoryPath
PartialSecretsPath = $partialSecretsPath
StoredSecretsPath = $storedSecretsPath
SecretsKeyPath = $secretsKeyPath
}
Initialize-DscPush @initDeploymentSettings
#endregion
#endregion Init
#region Infrastructure deployment
<#This region will deploy VM(s) to Hyper-V if the DeployInfrastructure switch is present.
This is put after the init section so that the password collection happens right after
the script starts and we don't have to wait for VMs to boot.
#>
if ($DeployInfrastructure)
{
$hyperVDeployScriptPath = "$WorkspacePath\deployVM-HyperV.ps1"
$deploymentParams = @{
VhdPath = $VhdPath
VSwitchName = $VSwitchName
HostIpAddress = $HostIpAddress
Credential = $DeploymentCredential
AdapterCount = 1
TargetSubnet = "255.255.255.0"
Clobber = $true
DifferencingDisks = $true
NodeDefinitionFilePath = $NodeDefinitionFilePath
}
& $hyperVDeployScriptPath @deploymentParams
}
#endregion
#region Publish - second step after getting your workspace setup is to publish DSC configurations
<#These are the recommended settings for initial deployments.
Follow up deployments can often turn off the CompSanitizeModulePaths, CopyContentStore & ForceResourceCopy switches to save time
This sample shows Mof Encryption via the $mofEncryptionSettings var.#>
$publishTargetSettings = @{
CompilePartials = $true
SanitizeModulePaths = $true
CopyContentStore = $true
ForceResourceCopy = $true
DeploymentCredential = $DeploymentCredential
ContentStoreRootPath = $contentStoreRootPath
ContentStoreDestPath = $ContentStoreDestPath
ContentStoreModulePath = $contentStoreModulePath
DscResourcesPath = $DscResourcesPath
NodeDefinitionFilePath = $NodeDefinitionFilePath
PartialCatalogPath = $partialCatalogPath
PartialDependenciesFilePath = $partialDependenciesFilePath
PartialSecretsPath = $partialSecretsPath
StoredSecretsPath = $storedSecretsPath
SecretsKeyPath = $secretsKeyPath
MofOutputPath = $mofOutputPath
TargetLcmSettings = $targetLCMSettings
}
$publishTargetSettings += $mofEncryptionSettings
Publish-TargetConfig @publishTargetSettings
#endregion Publish
#region Update Node Definition File
<# This section will allow for updating a Node Definition File from an existing Node Definition File, due to
an action requiring a re-examination of the variables stored in each Target Config object, any partial parameter
changes, etc. #>
<#
$UpdateNodeDefinitionFilePath = "$WorkspacePath\DSCPushSetup\DefinitionStore\NodeDefinitionCoreAppsTest.ps1"
$initDeploymentSettings = @{
GeneratePartialCatalog = $true
UpdateNodeDefinitionFile = $true
PartialCatalogPath = $partialCatalogPath
PartialStorePath = $partialStorePath
NodeDefinitionFilePath = $NodeDefinitionFilePath
UpdateNodeDefinitionFilePath = $UpdateNodeDefinitionFilePath
}
Initialize-DscPush @initDeploymentSettings
$NodeDefinitionFilePath = "$WorkspacePath\DSCPushSetup\DefinitionStore\NodeDefinition.ps1"
$publishTargetSettings = @{
CompilePartials = $true
SanitizeModulePaths = $false
CopyContentStore = $true
ForceResourceCopy = $true
DeploymentCredential = $DeploymentCredential
ContentStoreRootPath = $contentStoreRootPath
ContentStoreDestPath = $ContentStoreDestPath
ContentStoreModulePath = $contentStoreModulePath
DscResourcesPath = $DscResourcesPath
NodeDefinitionFilePath = $NodeDefinitionFilePath
PartialCatalogPath = $partialCatalogPath
PartialDependenciesFilePath = $partialDependenciesFilePath
PartialSecretsPath = $partialSecretsPath
StoredSecretsPath = $storedSecretsPath
SecretsKeyPath = $secretsKeyPath
MofOutputPath = $mofOutputPath
TargetLcmSettings = $targetLCMSettings
}
$publishTargetSettings += $mofEncryptionSettings
Publish-TargetConfig @publishTargetSettings #>
#endregion