forked from dsccommunity/JeaDsc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSC Diagnostic Demo Config.ps1
More file actions
196 lines (168 loc) · 5.1 KB
/
DSC Diagnostic Demo Config.ps1
File metadata and controls
196 lines (168 loc) · 5.1 KB
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
function Get-DscConfigurationVersion
{
$key = Get-Item HKLM:\SOFTWARE\DscTagging
$hash = @{ }
foreach ($property in $key.Property)
{
$hash.Add($property, $key.GetValue($property))
}
New-Object -TypeName PSObject -Property $hash
}
function Get-DscLcmControllerSettings
{
$key = Get-Item HKLM:\SOFTWARE\DscLcmController
$hash = @{ }
foreach ($property in $key.Property)
{
$hash.Add($property, $key.GetValue($property))
}
$maintenanceWindows = Get-ChildItem -Path HKLM:\SOFTWARE\DscLcmController\MaintenanceWindows
$maintenanceWindowsHash = @{ }
foreach ($maintenanceWindow in $maintenanceWindows)
{
$mwHash = @{ }
foreach ($property in $maintenanceWindow.Property)
{
$mwHash.Add($property, $maintenanceWindow.GetValue($property))
}
$maintenanceWindowsHash.Add($maintenanceWindow.PSChildName, $mwHash)
}
$hash.Add('MaintenanceWindows', (New-Object -TypeName PSObject -Property $maintenanceWindowsHash))
New-Object -TypeName PSObject -Property $hash
}
function Test-DscConfiguration
{
PSDesiredStateConfiguration\Test-DscConfiguration -Detailed -Verbose
}
function Update-DscConfiguration
{
PSDesiredStateConfiguration\Update-DscConfiguration -Wait -Verbose
}
function Get-DscLocalConfigurationManager
{
PSDesiredStateConfiguration\Get-DscLocalConfigurationManager
}
function Get-DscLcmControllerLog
{
param (
[Parameter()]
[switch]$AutoCorrect,
[Parameter()]
[switch]$Refresh,
[Parameter()]
[switch]$Monitor,
[Parameter()]
[int]$Last = 1000
)
Import-Csv -Path C:\ProgramData\Dsc\LcmController\LcmControllerSummary.txt | Where-Object {
if ($AutoCorrect)
{
[bool][int]$_.DoAutoCorrect -eq $AutoCorrect
}
else
{
$true
}
} | Where-Object {
if ($Refresh)
{
[bool][int]$_.DoRefresh -eq $Refresh
}
else
{
$true
}
} | Where-Object {
if ($Monitor)
{
[bool][int]$_.DoMonitor -eq $Monitor
}
else
{
$true
}
} | Microsoft.PowerShell.Utility\Select-Object -Last $Last
}
function Start-DscConfiguration
{
PSDesiredStateConfiguration\Start-DscConfiguration -UseExisting -Wait -Verbose
}
function Get-DscOperationalEventLog
{
Get-WinEvent -LogName "Microsoft-Windows-Dsc/Operational"
}
function Get-DscTraceInformation
{
param (
[Parameter()]
[int]$Last = 100
)
if (-not (Get-Module -ListAvailable -Name xDscDiagnostics))
{
Write-Error "This function required the module 'xDscDiagnostics' to be present on the system"
return
}
$failedJobs = Get-xDscOperation -Newest $Last | Where-Object Result -eq 'Failure'
foreach ($failedJob in $failedJobs)
{
if ($failedJob.JobID)
{
Trace-xDscOperation -JobId $failedJob.JobID
}
else
{
Trace-xDscOperation -SequenceID $failedJob.SequenceId
}
}
}
#-------------------------------------------------------------------------------------------
Configuration DscDiagnostic {
Import-DscResource -ModuleName JeaDsc
$visibleFunctions = 'Test-DscConfiguration',
'Get-DscConfigurationVersion',
'Update-DscConfiguration',
'Get-DscLcmControllerLog',
'Start-DscConfiguration',
'Get-DscOperationalEventLog',
'Get-DscTraceInformation',
'Get-DscLcmControllerSettings',
'Get-DscLocalConfigurationManager'
$functionDefinitions = @()
foreach ($visibleFunction in $visibleFunctions)
{
$functionDefinitions += @{
Name = $visibleFunction
ScriptBlock = (Get-Command -Name $visibleFunction).ScriptBlock
} | ConvertTo-Expression
}
JeaRoleCapabilities ReadDiagnosticRole
{
Path = 'C:\Program Files\WindowsPowerShell\Modules\DscDiagnostics\RoleCapabilities\ReadDiagnosticsRole.psrc'
VisibleFunctions = $visibleFunctions
FunctionDefinitions = $functionDefinitions
}
JeaSessionConfiguration DscEndpoint
{
Ensure = 'Present'
DependsOn = '[JeaRoleCapabilities]ReadDiagnosticRole'
Name = 'DSC'
RoleDefinitions = '@{ Everyone = @{ RoleCapabilities = "ReadDiagnosticsRole" } }'
SessionType = 'RestrictedRemoteServer'
ModulesToImport = 'PSDesiredStateConfiguration', 'xDscDiagnostics'
}
}
Get-PSSession | Remove-PSSession
Remove-Item -Path C:\DscTest\* -ErrorAction SilentlyContinue
DscDiagnostic -OutputPath C:\DscTest -Verbose
PSDesiredStateConfiguration\Start-DscConfiguration -Path C:\DscTest -Wait -Verbose -Force
$s = New-PSSession -ComputerName localhost -ConfigurationName DSC
Import-PSSession -Session $s -Prefix x
<#
The follwoing cmdlets will be available after importing the session
Get-xDscConfigurationVersion
Update-xDscConfiguration
Get-xDscLcmControllerLog
Get-DscLcmControllerSettings
Get-DscOperationalEventLog
Get-DscTraceInformation
#>