-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Start-Testing.ps1
478 lines (448 loc) · 29.1 KB
/
Start-Testing.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
function Start-Testing {
<#
.SYNOPSIS
This function initiates the testing process based on the specified scope.
.DESCRIPTION
Start-Testing function is used to start the testing process with the provided parameters. It sets the appropriate levels based on the scope and retrieves configuration details for testing.
.PARAMETER Execute
Specifies the script block to execute during testing.
.PARAMETER Scope
Specifies the scope of the testing process (Forest, Domain, DC).
.PARAMETER Domain
Specifies the domain for the testing process.
.PARAMETER DomainController
Specifies the domain controller for the testing process.
.PARAMETER IsPDC
Specifies if the domain controller is a Primary Domain Controller.
.PARAMETER ForestInformation
Specifies information related to the forest for testing.
.PARAMETER DomainInformation
Specifies information related to the domain for testing.
.PARAMETER ForestDetails
Specifies additional details related to the forest for testing.
.PARAMETER SkipRODC
Skips Read-Only Domain Controller testing.
.PARAMETER Variables
Specifies additional variables for testing.
.EXAMPLE
Start-Testing -Execute { Write-Host "Testing in progress..." } -Scope "Domain" -Domain "example.com" -DomainController "DC1" -IsPDC $true -ForestInformation $ForestInfo -DomainInformation $DomainInfo -ForestDetails @{"Detail1"="Value1"} -SkipRODC -Variables @{"Var1"="Value1"}
#>
[CmdletBinding()]
param(
[ScriptBlock] $Execute,
[string] $Scope,
[string] $Domain,
[string] $DomainController,
[bool] $IsPDC,
[Object] $ForestInformation,
[Object] $DomainInformation,
[System.Collections.IDictionary] $ForestDetails,
[switch] $SkipRODC,
[System.Collections.IDictionary] $Variables
)
$GlobalTime = Start-TimeLog
if ($Scope -eq 'Forest') {
$Level = 3
$LevelTest = 6
$LevelSummary = 3
$LevelTestFailure = 6
$Config = $Script:TestimoConfiguration['ActiveDirectory']
$SummaryText = "Forest"
} elseif ($Scope -eq 'Domain') {
$Level = 6
$LevelTest = 9
$LevelSummary = 6
$LevelTestFailure = 9
$Config = $Script:TestimoConfiguration['ActiveDirectory']
Write-Color
$SummaryText = "Domain $Domain"
} elseif ($Scope -eq 'DC') {
$Level = 9
$LevelTest = 12
$LevelSummary = 9
$LevelTestFailure = 12
$Config = $Script:TestimoConfiguration['ActiveDirectory']
$SummaryText = "Domain $Domain, $DomainController"
} else {
$Level = 3
$LevelTest = 6
$LevelSummary = 3
$LevelTestFailure = 6
$Config = $Script:TestimoConfiguration[$Scope]
Write-Color
$SummaryText = $Scope
}
# Build requirements variables
[bool] $IsDomainRoot = $ForestInformation.Name -eq $Domain
# Out-Begin -Type 'i' -Text $SummaryText -Level ($LevelSummary - 3) -Domain $Domain -DomainController $DomainController
# Out-Status -Text $SummaryText -Status $null -ExtendedValue '' -Domain $Domain -DomainController $DomainController
Out-Informative -Scope $Scope -Text $SummaryText -Status $null -ExtendedValue '' -Domain $Domain -DomainController $DomainController -Level ($LevelSummary - 3)
$TestsSummaryTogether = @(
foreach ($Source in $Config.Keys) {
if ($Scope -ne $Config[$Source].Scope) {
continue
}
$CurrentSection = $Config[$Source]
if ($null -eq $CurrentSection) {
# Probably should write some tests
Write-Warning "Source $Source in scope: $Scope is defined improperly. Please verify."
continue
}
if ($CurrentSection['Enable'] -eq $true) {
$Time = Start-TimeLog
$CurrentSource = $CurrentSection['Source']
#$CurrentTests = $CurrentSection['Tests']
[Array] $AllTests = $CurrentSection['Tests'].Keys
$ReferenceID = $Source #Get-RandomStringName -Size 8
$TestsSummary = [PSCustomobject] @{
Passed = 0
Failed = 0
Skipped = 0
Total = 0 # $AllTests.Count + 1 # +1 includes availability of data test
}
# build data output for extended results
$TestOutput = [ordered] @{
Name = $CurrentSource['Name']
SourceCode = if ($CurrentSource['Data']) { $CurrentSource['Data'] } else { $null }
Details = $CurrentSource['Details']
Results = [System.Collections.Generic.List[PSCustomObject]]::new()
Domain = $Domain
DomainController = $DomainController
}
# Lets divide tests results into by type Forest/Domain/Domain Controller
if ($Scope -in 'Forest', 'Domain', 'DC') {
if ($Domain -and $DomainController) {
$Script:Reporting['Domains'][$Domain]['DomainControllers'][$DomainController]['Tests'][$ReferenceID] = $TestOutput
} elseif ($Domain) {
$Script:Reporting['Domains'][$Domain]['Tests'][$ReferenceID] = $TestOutput
} else {
$Script:Reporting['Forest']['Tests'][$ReferenceID] = $TestOutput
}
} else {
$Script:Reporting[$Scope]['Tests'][$ReferenceID] = $TestOutput
}
# Lets divide tests by source (same content/different way to use later on)
#if (-not $Script:Reporting['BySource'][$Source]) {
# $Script:Reporting['BySource'][$Source] = [System.Collections.Generic.List[PSCustomObject]]::new()
#}
#$Script:Reporting['BySource'][$Source].Add($TestOutput)
$Script:Reporting['BySource'][$Source] = $TestOutput
if (-not $CurrentSection['Source']) {
Write-Warning "Source $Source in scope: $Scope is defined improperly. Please verify."
continue
}
# Check if requirements are met
if ($CurrentSource['Requirements']) {
if ($null -ne $CurrentSource['Requirements']['IsDomainRoot']) {
if (-not $CurrentSource['Requirements']['IsDomainRoot'] -eq $IsDomainRoot) {
Out-Skip -Scope $Scope -Test $CurrentSource['Name'] -DomainController $DomainController -Domain $Domain -TestsSummary $TestsSummary -Source $ReferenceID -Level $Level
continue
}
}
if ($null -ne $CurrentSource['Requirements']['IsPDC']) {
if (-not $CurrentSource['Requirements']['IsPDC'] -eq $IsPDC) {
Out-Skip -Scope $Scope -Test $CurrentSource['Name'] -DomainController $DomainController -Domain $Domain -TestsSummary $TestsSummary -Source $ReferenceID -Level $Level
continue
}
}
if ($null -ne $CurrentSource['Requirements']['OperatingSystem']) {
}
if ($null -ne $CurrentSource['Requirements']['CommandAvailable']) {
[Array] $Commands = foreach ($Command in $CurrentSource['Requirements']['CommandAvailable']) {
$OutputCommand = Get-Command -Name $Command -ErrorAction SilentlyContinue
if (-not $OutputCommand) {
$false
}
}
if ($Commands -contains $false) {
$CommandsTested = $CurrentSource['Requirements']['CommandAvailable'] -join ', '
Out-Skip -Scope $Scope -Test $CurrentSource['Name'] -DomainController $DomainController -Domain $Domain -TestsSummary $TestsSummary -Source $ReferenceID -Level $Level -Reason "Skipping - At least one command unavailable ($CommandsTested)"
continue
}
}
if ($null -ne $CurrentSource['Requirements']['IsInternalForest']) {
if ($CurrentSource['Requirements']['IsInternalForest'] -eq $true) {
if ($ForestName) {
Out-Skip -Scope $Scope -Test $CurrentSource['Name'] -DomainController $DomainController -Domain $Domain -TestsSummary $TestsSummary -Source $ReferenceID -Level $Level -Reason "Skipping - External forest requested. Not supported test."
continue
}
}
}
}
# START - Execute TEST - By getting the Data SOURCE
Out-Informative -Scope $Scope -Text $CurrentSource['Name'] -Level $Level -Domain $Domain -DomainController $DomainController -Start
if ($CurrentSource['Parameters']) {
$SourceParameters = $CurrentSource['Parameters']
} else {
$SourceParameters = @{}
}
if ($Scope -in 'Forest', 'Domain', 'DC') {
$SourceParameters['DomainController'] = $DomainController
if ($Scope -eq 'Forest') {
$SourceParameters['QueryServer'] = $ForestDetails['QueryServers']['Forest']['HostName'][0]
} else {
$SourceParameters['QueryServer'] = $ForestDetails['QueryServers'][$Domain]['HostName'][0]
}
$SourceParameters['Domain'] = $Domain
$SourceParameters['ForestDetails'] = $ForestDetails
$SourceParameters['ForestName'] = $ForestInformation.Name
$SourceParameters['DomainInformation'] = $DomainInformation
$SourceParameters['ForestInformation'] = $ForestInformation
$SourceParameters['SkipRODC'] = $SkipRODC.IsPresent # bool true/false
} else {
$SourceParameters['Authorization'] = $Script:AuthorizationO365Cache
$SourceParameters['Session'] = Get-PSSession | Where-Object { $_.ComputerName -eq 'outlook.office365.com' -and $_.State -eq 'Opened' } | Select-Object -First 1
}
foreach ($Variable in $Variables.Keys) {
$SourceParameters[$Variable] = $Variables[$Variable]
}
if ($CurrentSource['Data'] -is [ScriptBlock]) {
if ($Script:TestimoConfiguration.Debug.ShowErrors) {
$OutputData = & $CurrentSource['Data'] -DomainController $DomainController -Domain $Domain
$OutputInvoke = @{
Output = $OutputData
}
$ErrorMessage = $null
} else {
$OutputInvoke = Invoke-CommandCustom -ScriptBlock $CurrentSource['Data'] -Parameter $SourceParameters -ReturnVerbose -ReturnError -ReturnWarning -AddParameter
if ($OutputInvoke.Error) {
$ErrorMessage = $OutputInvoke.Error.Exception.Message -replace "`n", " " -replace "`r", " "
} else {
$ErrorMessage = $null
}
}
} else {
$OutputInvoke = @{
Output = $CurrentSource['DataOutput']
}
}
$WarningsAndErrors = @(
#if ($ShowWarning) {
foreach ($War in $OutputInvoke.Warning) {
[PSCustomObject] @{
Type = 'Warning'
Comment = $War
Reason = ''
TargetName = ''
}
}
#}
#if ($ShowError) {
foreach ($Err in $OutputInvoke.Error) {
[PSCustomObject] @{
Type = 'Error'
Comment = $Err
Reason = $Err.CategoryInfo.Reason
TargetName = $Err.CategoryInfo.TargetName
}
}
#}
)
Out-Informative -Scope $Scope -Text $CurrentSource['Name'] -Status $null -ExtendedValue $null -Domain $Domain -DomainController $DomainController -End
# END - Execute TEST - By getting the Data SOURCE
$Object = $OutputInvoke.Output
if ($CurrentSource['Flatten'] -and $Object) {
$Object = $Object | ConvertTo-FlatObject
}
# Add data output to extended results
if ($Scope -in 'Forest', 'Domain', 'DC') {
if ($Domain -and $DomainController) {
$Script:Reporting['Domains'][$Domain]['DomainControllers'][$DomainController]['Tests'][$ReferenceID]['Data'] = $Object
$Script:Reporting['Domains'][$Domain]['DomainControllers'][$DomainController]['Tests'][$ReferenceID]['Verbose'] = $OutputInvoke.Verbose
$Script:Reporting['Domains'][$Domain]['DomainControllers'][$DomainController]['Tests'][$ReferenceID]['Warning'] = $OutputInvoke.Warning
$Script:Reporting['Domains'][$Domain]['DomainControllers'][$DomainController]['Tests'][$ReferenceID]['Error'] = $OutputInvoke.Error
$Script:Reporting['Domains'][$Domain]['DomainControllers'][$DomainController]['Tests'][$ReferenceID]['WarningsAndErrors'] = $WarningsAndErrors
$Script:Reporting['Domains'][$Domain]['DomainControllers'][$DomainController]['Tests'][$ReferenceID]['DetailsTests'] = [ordered]@{ }
$Script:Reporting['Domains'][$Domain]['DomainControllers'][$DomainController]['Tests'][$ReferenceID]['ResultsTests'] = [ordered]@{ }
$Script:Reporting['Domains'][$Domain]['DomainControllers'][$DomainController]['Tests'][$ReferenceID]['Information'] = $CurrentSection
} elseif ($Domain) {
$Script:Reporting['Domains'][$Domain]['Tests'][$ReferenceID]['Data'] = $Object
$Script:Reporting['Domains'][$Domain]['Tests'][$ReferenceID]['Verbose'] = $OutputInvoke.Verbose
$Script:Reporting['Domains'][$Domain]['Tests'][$ReferenceID]['Warning'] = $OutputInvoke.Warning
$Script:Reporting['Domains'][$Domain]['Tests'][$ReferenceID]['Error'] = $OutputInvoke.Error
$Script:Reporting['Domains'][$Domain]['Tests'][$ReferenceID]['WarningsAndErrors'] = $WarningsAndErrors
$Script:Reporting['Domains'][$Domain]['Tests'][$ReferenceID]['DetailsTests'] = [ordered]@{ }
$Script:Reporting['Domains'][$Domain]['Tests'][$ReferenceID]['ResultsTests'] = [ordered]@{ }
$Script:Reporting['Domains'][$Domain]['Tests'][$ReferenceID]['Information'] = $CurrentSection
} else {
$Script:Reporting['Forest']['Tests'][$ReferenceID]['Data'] = $Object
$Script:Reporting['Forest']['Tests'][$ReferenceID]['Verbose'] = $OutputInvoke.Verbose
$Script:Reporting['Forest']['Tests'][$ReferenceID]['Warning'] = $OutputInvoke.Warning
$Script:Reporting['Forest']['Tests'][$ReferenceID]['Error'] = $OutputInvoke.Error
$Script:Reporting['Forest']['Tests'][$ReferenceID]['WarningsAndErrors'] = $WarningsAndErrors
$Script:Reporting['Forest']['Tests'][$ReferenceID]['DetailsTests'] = [ordered]@{ }
$Script:Reporting['Forest']['Tests'][$ReferenceID]['ResultsTests'] = [ordered]@{ }
$Script:Reporting['Forest']['Tests'][$ReferenceID]['Information'] = $CurrentSection
}
} else {
$Script:Reporting[$Scope]['Tests'][$ReferenceID]['Data'] = $Object
$Script:Reporting[$Scope]['Tests'][$ReferenceID]['Verbose'] = $OutputInvoke.Verbose
$Script:Reporting[$Scope]['Tests'][$ReferenceID]['Warning'] = $OutputInvoke.Warning
$Script:Reporting[$Scope]['Tests'][$ReferenceID]['Error'] = $OutputInvoke.Error
$Script:Reporting[$Scope]['Tests'][$ReferenceID]['WarningsAndErrors'] = $WarningsAndErrors
$Script:Reporting[$Scope]['Tests'][$ReferenceID]['DetailsTests'] = [ordered]@{ }
$Script:Reporting[$Scope]['Tests'][$ReferenceID]['ResultsTests'] = [ordered]@{ }
$Script:Reporting[$Scope]['Tests'][$ReferenceID]['Information'] = $CurrentSection
}
# If there's no output from Source Data all other tests will fail
if ($ErrorMessage) {
$FailAllTests = $true
$ExtendedValue = $ErrorMessage -join "; "
Out-Failure -Scope $Scope -Text $CurrentSource['Name'] -Level $LevelTest -ExtendedValue $ExtendedValue -Domain $Domain -DomainController $DomainController -ReferenceID $ReferenceID -Source $CurrentSource
$TestsSummary.Failed = $TestsSummary.Failed + 1
} elseif ($Object -and $CurrentSource['ExpectedOutput'] -eq $true) {
# Output is provided and we did expect it - passed test
$FailAllTests = $false
Out-Begin -Scope $Scope -Text $CurrentSource['Name'] -Level $LevelTest -Domain $Domain -DomainController $DomainController
Out-Status -Scope $Scope -Text $CurrentSource['Name'] -Status $true -ExtendedValue 'Data is available' -Domain $Domain -DomainController $DomainController -ReferenceID $ReferenceID -Source $CurrentSource
$TestsSummary.Passed = $TestsSummary.Passed + 1
} elseif ($Object -and $CurrentSource['ExpectedOutput'] -eq $false) {
# Output is provided, but we expected no output - failing test
$FailAllTests = $false
Out-Failure -Scope $Scope -Text $CurrentSource['Name'] -Level $LevelTest -ExtendedValue 'Data is available. This is a bad thing' -Domain $Domain -DomainController $DomainController -ReferenceID $ReferenceID -Source $CurrentSource
$TestsSummary.Failed = $TestsSummary.Failed + 1
} elseif ($Object -and $null -eq $CurrentSource['ExpectedOutput']) {
# Output is provided, but we weren't sure if there should be output or not
$FailAllTests = $false
Out-Begin -Scope $Scope -Text $CurrentSource['Name'] -Level $LevelTest -Domain $Domain -DomainController $DomainController
Out-Status -Scope $Scope -Text $CurrentSource['Name'] -Status $null -ExtendedValue 'Data is available' -Domain $Domain -DomainController $DomainController -ReferenceID $ReferenceID -Source $CurrentSource
#$TestsSummary.Passed = $TestsSummary.Passed + 1
$TestsSummary.Skipped = $TestsSummary.Skipped + 1
} elseif ($null -eq $Object -and $CurrentSource['ExpectedOutput'] -eq $true) {
# Output was not provided and we expected it
$FailAllTests = $true
Out-Failure -Scope $Scope -Text $CurrentSource['Name'] -Level $LevelTest -ExtendedValue 'No data available' -Domain $Domain -DomainController $DomainController -ReferenceID $ReferenceID -Source $CurrentSource
$TestsSummary.Failed = $TestsSummary.Failed + 1
} elseif ($null -eq $Object -and $CurrentSource['ExpectedOutput'] -eq $false) {
# This tests whether there was an output from Source or not.
# Sometimes it makes sense to ask for data and get null/empty in return
# you just need to make sure to define ExpectedOutput = $false in source definition
$FailAllTests = $false
Out-Begin -Scope $Scope -Text $CurrentSource['Name'] -Level $LevelTest -Domain $Domain -DomainController $DomainController
Out-Status -Scope $Scope -Text $CurrentSource['Name'] -Status $true -ExtendedValue 'No data returned, which is a good thing' -Domain $Domain -DomainController $DomainController -ReferenceID $ReferenceID -Source $CurrentSource
$TestsSummary.Passed = $TestsSummary.Passed + 1
} elseif ($null -eq $Object -and $null -eq $CurrentSource['ExpectedOutput']) {
# Output is not provided, but we weren't sure if there should be output or not
$FailAllTests = $false
Out-Begin -Scope $Scope -Text $CurrentSource['Name'] -Level $LevelTest -Domain $Domain -DomainController $DomainController
Out-Status -Scope $Scope -Text $CurrentSource['Name'] -Status $null -ExtendedValue 'No data returned' -Domain $Domain -DomainController $DomainController -ReferenceID $ReferenceID -Source $CurrentSource
# $TestsSummary.Passed = $TestsSummary.Passed + 1
$TestsSummary.Skipped = $TestsSummary.Skipped + 1
} else {
$FailAllTests = $true
Out-Failure -Scope $Scope -Text $CurrentSource['Name'] -Level $LevelTest -ExtendedValue 'No data available' -Domain $Domain -DomainController $DomainController -ReferenceID $ReferenceID -Source $CurrentSource
$TestsSummary.Failed = $TestsSummary.Failed + 1
}
foreach ($Test in $AllTests) {
# Add content with description of the test
if ($Scope -in 'Forest', 'Domain', 'DC') {
if ($Domain -and $DomainController) {
$Script:Reporting['Domains'][$Domain]['DomainControllers'][$DomainController]['Tests'][$ReferenceID]['DetailsTests'][$Test] = $CurrentSection['Tests'][$Test]['Details']
} elseif ($Domain) {
$Script:Reporting['Domains'][$Domain]['Tests'][$ReferenceID]['DetailsTests'][$Test] = $CurrentSection['Tests'][$Test]['Details']
} else {
$Script:Reporting['Forest']['Tests'][$ReferenceID]['DetailsTests'][$Test] = $CurrentSection['Tests'][$Test]['Details']
}
} else {
$Script:Reporting[$Scope]['Tests'][$ReferenceID]['DetailsTests'][$Test] = $CurrentSection['Tests'][$Test]['Details']
}
$CurrentTest = $CurrentSection['Tests'][$Test]
if ($CurrentTest['Enable'] -eq $True) {
# Check for requirements
if ($CurrentTest['Requirements']) {
if ($null -ne $CurrentTest['Requirements']['IsDomainRoot']) {
if (-not $CurrentTest['Requirements']['IsDomainRoot'] -eq $IsDomainRoot) {
$TestsSummary.Skipped = $TestsSummary.Skipped + 1
continue
}
}
if ($null -ne $CurrentTest['Requirements']['IsPDC']) {
if (-not $CurrentTest['Requirements']['IsPDC'] -eq $IsPDC) {
$TestsSummary.Skipped = $TestsSummary.Skipped + 1
continue
}
}
}
if (-not $FailAllTests) {
$testStepOneSplat = @{
Test = $CurrentTest
Object = $Object
Domain = $Domain
DomainController = $DomainController
Level = $LevelTest
TestName = $CurrentTest['Name']
ReferenceID = $ReferenceID
Requirements = $CurrentTest['Requirements']
Scope = $Scope
}
# We provide whatever parameters are available in Data Source to Tests (mainly for use within WhereObject)
#if ($CurrentSource['Parameters']) {
# $testStepOneSplat['Parameters'] = $CurrentSource['Parameters']
#}
if ($Scope -in 'Forest', 'Domain', 'DC') {
if ($Scope -eq 'Forest') {
$testStepOneSplat['QueryServer'] = $ForestDetails['QueryServers']['Forest']['HostName'][0]
} else {
$testStepOneSplat['QueryServer'] = $ForestDetails['QueryServers'][$Domain]['HostName'][0]
}
$testStepOneSplat['ForestDetails'] = $ForestDetails
$testStepOneSplat['ForestName'] = $ForestInformation.Name
$testStepOneSplat['DomainInformation'] = $DomainInformation
$testStepOneSplat['ForestInformation'] = $ForestInformation
}
$TestsResults = Test-StepOne @testStepOneSplat
$TestsSummary.Passed = $TestsSummary.Passed + ($TestsResults | Where-Object { $_ -eq $true }).Count
$TestsSummary.Failed = $TestsSummary.Failed + ($TestsResults | Where-Object { $_ -eq $false }).Count
} else {
$TestsResults = $null
$TestsSummary.Failed = $TestsSummary.Failed + 1
Out-Failure -Scope $Scope -Text $CurrentTest['Name'] -Level $LevelTestFailure -Domain $Domain -DomainController $DomainController -ReferenceID $ReferenceID -ExtendedValue 'Input data not provided. Failing test.' -Source $CurrentTest
}
if ($Scope -in 'Forest', 'Domain', 'DC') {
if ($Domain -and $DomainController) {
$Script:Reporting['Domains'][$Domain]['DomainControllers'][$DomainController]['Tests'][$ReferenceID]['ResultsTests'][$Test] = $TestsResults
} elseif ($Domain) {
$Script:Reporting['Domains'][$Domain]['Tests'][$ReferenceID]['ResultsTests'][$Test] = $TestsResults
} else {
$Script:Reporting['Forest']['Tests'][$ReferenceID]['ResultsTests'][$Test] = $TestsResults
}
} else {
$Script:Reporting[$Scope]['Tests'][$ReferenceID]['ResultsTests'][$Test] = $TestsResults
}
} else {
$TestsSummary.Skipped = $TestsSummary.Skipped + 1
}
}
$TestsSummary.Total = $TestsSummary.Failed + $TestsSummary.Passed + $TestsSummary.Skipped
$TestsSummary
Out-Summary -Scope $Scope -Text $CurrentSource['Name'] -Time $Time -Level $LevelSummary -Domain $Domain -DomainController $DomainController -TestsSummary $TestsSummary
}
}
if ($Execute) {
& $Execute
}
)
$TestsSummaryFinal = [PSCustomObject] @{
Passed = ($TestsSummaryTogether.Passed | Measure-Object -Sum).Sum
Failed = ($TestsSummaryTogether.Failed | Measure-Object -Sum).Sum
Skipped = ($TestsSummaryTogether.Skipped | Measure-Object -Sum).Sum
Total = ($TestsSummaryTogether.Total | Measure-Object -Sum).Sum
}
$TestsSummaryFinal
if ($Scope -in 'Forest', 'Domain', 'DC') {
if ($Domain -and $DomainController) {
$Script:Reporting['Domains'][$Domain]['DomainControllers'][$DomainController]['Summary'] = $TestsSummaryFinal
} elseif ($Domain) {
$Script:Reporting['Domains'][$Domain]['Summary'] = $TestsSummaryFinal
} else {
if ($Scope -ne 'Forest') {
$Script:Reporting['Summary'] = $TestsSummaryFinal
} else {
$Script:Reporting['Forest']['Summary'] = $TestsSummaryFinal
}
}
} else {
$Script:Reporting[$Scope]['Summary'] = $TestsSummaryFinal
}
Out-Summary -Scope $Scope -Text $SummaryText -Time $GlobalTime -Level ($LevelSummary - 3) -Domain $Domain -DomainController $DomainController -TestsSummary $TestsSummaryFinal
}