-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathMSFT_xWebAppPoolDefaults.psm1
More file actions
246 lines (208 loc) · 5.98 KB
/
MSFT_xWebAppPoolDefaults.psm1
File metadata and controls
246 lines (208 loc) · 5.98 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
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
# Suppressing this rule because Write-Verbose is called in Helper functions
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSDSCUseVerboseMessageInDSCResource', '')]
param ()
# Load the Helper Module
Import-Module -Name "$PSScriptRoot\..\Helper.psm1"
# Localized messages
data LocalizedData
{
# culture="en-US"
ConvertFrom-StringData -StringData @'
NoWebAdministrationModule = Please ensure that WebAdministration module is installed.
SettingValue = Changing default value '{0}' to '{1}'
ValueOk = Default value '{0}' is already '{1}'
VerboseGetTargetResource = Get-TargetResource has been run.
'@
}
<#
.SYNOPSIS
This will return a hashtable of results
#>
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet('Machine')]
[System.String]
$ApplyTo
)
Assert-Module
Write-Verbose -Message $LocalizedData.VerboseGetTargetResource
return @{
ManagedRuntimeVersion = (Get-Value -Path '' -Name 'managedRuntimeVersion')
IdentityType = (Get-Value -Path 'processModel' -Name 'identityType')
}
}
<#
.SYNOPSIS
This will set the desired state
#>
function Set-TargetResource
{
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSDSCUseVerboseMessageInDSCResource", "")]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet('Machine')]
[System.String]
$ApplyTo,
[Parameter()]
[ValidateSet('','v2.0','v4.0')]
[System.String]
$ManagedRuntimeVersion,
[Parameter()]
[ValidateSet('ApplicationPoolIdentity','LocalService','LocalSystem','NetworkService')]
[System.String]
$IdentityType
)
Assert-Module
Set-Value -Path '' -Name 'managedRuntimeVersion' -NewValue $ManagedRuntimeVersion
Set-Value -Path 'processModel' -Name 'identityType' -NewValue $IdentityType
}
<#
.SYNOPSIS
This tests the desired state. If the state is not correct it will return $false.
If the state is correct it will return $true
#>
function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSDSCUseVerboseMessageInDSCResource", "")]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet('Machine')]
[System.String]
$ApplyTo,
[Parameter()]
[ValidateSet('','v2.0','v4.0')]
[System.String]
$ManagedRuntimeVersion,
[Parameter()]
[ValidateSet('ApplicationPoolIdentity','LocalService','LocalSystem','NetworkService')]
[System.String]
$IdentityType
)
Assert-Module
if (-not((Confirm-Value -Path '' `
-Name 'managedRuntimeVersion' `
-NewValue $ManagedRuntimeVersion)))
{
return $false
}
if (-not((Confirm-Value -Path 'processModel' `
-Name 'identityType' `
-NewValue $IdentityType)))
{
return $false
}
return $true
}
#region Helper Functions
function Confirm-Value
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[System.String]
$Path,
[Parameter(Mandatory = $true)]
[System.String]
$Name,
[Parameter()]
[System.String]
$NewValue
)
if (-not $NewValue)
{
# if no new value was specified, we assume this value is okay.
return $true
}
$existingValue = Get-Value -Path $Path -Name $Name
if ($existingValue -ne $NewValue)
{
return $false
}
else
{
$relPath = $Path + '/' + $Name
Write-Verbose($LocalizedData.ValueOk -f $relPath, $NewValue);
return $true
}
}
function Set-Value
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[System.String]
$Path,
[Parameter(Mandatory = $true)]
[System.String]
$Name,
[Parameter()]
[System.String]
$NewValue
)
# if the variable doesn't exist, the user doesn't want to change this value
if (-not $NewValue)
{
return
}
$existingValue = Get-Value -Path $Path -Name $Name
if ($existingValue -ne $NewValue)
{
if ($Path -ne '')
{
$Path = '/' + $Path
}
Set-WebConfigurationProperty `
-PSPath 'MACHINE/WEBROOT/APPHOST' `
-Filter "system.applicationHost/applicationPools/applicationPoolDefaults$Path" `
-Name $Name `
-Value "$NewValue"
$relPath = $Path + '/' + $Name
Write-Verbose($LocalizedData.SettingValue -f $relPath,$NewValue);
}
}
function Get-Value
{
[CmdletBinding()]
[OutputType([PSObject])]
param
(
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[System.String]
$Path,
[Parameter(Mandatory = $true)]
[System.String]
$Name
)
if ($Path -ne '')
{
$Path = '/' + $Path
}
$result = Get-WebConfigurationProperty `
-PSPath 'MACHINE/WEBROOT/APPHOST' `
-Filter "system.applicationHost/applicationPools/applicationPoolDefaults$Path" `
-Name $Name
if ($result -is [Microsoft.IIs.PowerShell.Framework.ConfigurationAttribute])
{
return $result.Value
} else {
return $result
}
}
#endregion
Export-ModuleMember -Function *-TargetResource