@@ -106,53 +106,101 @@ Function Setup-Lab {
106
106
# endregion Setup-lab
107
107
108
108
# region Run-Lab
109
- Function Run-Lab {
110
- Param (
111
- [string ]$Path = $PSScriptRoot
112
- )
113
-
114
- Write-Host - ForegroundColor Green - Object @"
115
-
116
- This is the Run-Lab script. This script will perform the following:
117
-
118
- * Start the Lab environment
119
-
120
- Note! If this is the first time you have run this, it can take up to an hour
121
- for the DSC configs to apply.
122
- This only occurs the first time.
123
-
124
- "@
125
-
126
- Write-Host - ForegroundColor Cyan - Object ' Starting the lab environment'
127
- # Creates the lab environment without making a Hyper-V Snapshot
128
- Start-Lab - ConfigurationData .\* .psd1
129
-
130
- Write-Host - ForegroundColor Green - Object @"
131
-
132
- Next Steps:
133
-
134
- Run the following to validatae when configurations have converged:
135
- Validate-Lab
136
-
137
- To enable Internet access for the VM's, run:
138
- Enable-Internet
139
-
140
- To stop the lab VM's:
141
- Shutdown-lab
142
-
143
- When the configurations have finished, you can checkpoint the VM's with:
144
- Snapshot-Lab
145
-
146
- To quickly rebuild the labs from the checkpoint, run:
147
- Refresh-Lab
148
-
149
- To destroy the lab to build again:
150
- Wipe-Lab
151
-
152
-
153
- "@
154
- }
155
- # endregion setup-lab
109
+ Function Setup-Lab {
110
+ [cmdletbinding (SupportsShouldProcess )]
111
+ Param (
112
+ [string ]$Path = $PSScriptRoot ,
113
+ [switch ]$IgnorePendingReboot
114
+ )
115
+
116
+ Write-Host - ForegroundColor Green - Object @"
117
+
118
+ This is the Setup-Lab script. This script will perform the following:
119
+ * Run the configs to generate the required .mof files
120
+ Note! - If there is an error creating the .mofs, the setup will fail
121
+
122
+ * Run the lab setup
123
+ Note! If this is the first time you have run this, it can take several
124
+ hours to download the .ISO's and resources.
125
+ This only occurs the first time.
126
+
127
+ **Possible problem, if the downloads finish but the script doesn't continue (pauses)
128
+ Hit the return key once and it will continue
129
+
130
+ *You will be able to wipe and rebuild this lab without needing to perform
131
+ the downloads again.
132
+ "@
133
+
134
+ # Install DSC Resource modules specified in the .PSD1
135
+ Write-Host - ForegroundColor Cyan - Object ' Installing required DSCResource modules from PSGallery'
136
+ Write-Host - ForegroundColor Yellow - Object ' You may need to say "yes" to a Nuget Provider'
137
+ $LabData = Import-PowerShellDataFile - Path .\* .psd1
138
+ $DSCResources = $LabData.NonNodeData.Lability.DSCResource
139
+
140
+ Foreach ($DSCResource in $DSCResources ) {
141
+
142
+ Install-Module - Name $ ($DSCResource ).Name - RequiredVersion $ ($DSCResource ).RequiredVersion
143
+
144
+ }
145
+
146
+ # Run the config to generate the .mof files
147
+ Write-Host - ForegroundColor Cyan - Object ' Build the .Mof files from the configs'
148
+ if ($PSCmdlet.ShouldProcess (' .\VMConfiguration.ps1' )) {
149
+ .\VMConfiguration.ps1
150
+ }
151
+ # Build the lab without a snapshot
152
+ #
153
+ Write-Host - ForegroundColor Cyan - Object ' Building the lab environment'
154
+ # Creates the lab environment without making a Hyper-V Snapshot
155
+
156
+ $Password = ConvertTo-SecureString - String " $ ( $labdata.allnodes.labpassword ) " - AsPlainText - Force
157
+ $startParams = @ {
158
+ ConfigurationData = " .\*.psd1"
159
+ Path = " .\"
160
+ NoSnapshot = $True
161
+ Password = $Password
162
+ }
163
+ if ($IgnorePendingReboot ) {
164
+ $startParams.Add (" IgnorePendingReboot" , $True )
165
+ }
166
+
167
+ if ($PSCmdlet.ShouldProcess ($ ($startParams | Out-String ))) {
168
+ Start-LabConfiguration @startParams
169
+ # Disable secure boot for VM's
170
+ Get-VM ( Get-LabVM - ConfigurationData .\* .psd1 ).Name - OutVariable vm
171
+ Set-VMFirmware - VM $vm - EnableSecureBoot Off - SecureBootTemplate MicrosoftUEFICertificateAuthority
172
+
173
+
174
+ Write-Host - ForegroundColor Green - Object @"
175
+
176
+ Next Steps:
177
+
178
+ When complete, run:
179
+ Run-Lab
180
+
181
+ Run the following to validatae when configurations have converged:
182
+ Validate-Lab
183
+
184
+ To enable Internet access for the VM's, run:
185
+ Enable-Internet
186
+
187
+ To stop the lab VM's:
188
+ Shutdown-lab
189
+
190
+ When the configurations have finished, you can checkpoint the VM's with:
191
+ Snapshot-Lab
192
+
193
+ To quickly rebuild the labs from the checkpoint, run:
194
+ Refresh-Lab
195
+
196
+ To destroy the lab to build again:
197
+ Wipe-Lab
198
+
199
+ "@
200
+
201
+ } # should process
202
+
203
+ }# endregion setup-lab
156
204
157
205
# region Enable-Internet
158
206
Function Enable-Internet {
@@ -418,9 +466,11 @@ Function Wipe-Lab {
418
466
419
467
# region Unattend-Lab
420
468
Function Unattend-Lab {
421
- Param (
422
- [string ]$Path = $PSScriptRoot
423
- )
469
+ [cmdletbinding (SupportsShouldProcess )]
470
+ Param (
471
+ [string ]$Path = $PSScriptRoot ,
472
+ [switch ]$IgnorePendingReboot
473
+ )
424
474
425
475
Write-Host - ForegroundColor Green - Object @"
426
476
@@ -431,7 +481,7 @@ Function Unattend-Lab {
431
481
Write-Host - ForegroundColor Cyan - Object ' Starting the lab environment'
432
482
433
483
434
- Setup- Lab
484
+ Setup- Lab @psboundparameters
435
485
Run- Lab
436
486
Enable-Internet
437
487
Validate- Lab
0 commit comments