-
Notifications
You must be signed in to change notification settings - Fork 14
/
Get-WebConfigurationSetting.ps1
51 lines (43 loc) · 3.36 KB
/
Get-WebConfigurationSetting.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
function Get-WebConfigurationSetting
{
<#
.Synopsis
Gets settings from web configuration
.Description
Gets appSettings from web configuration file
.Example
Get-WebConfigurationSetting "MySetting"
.Link
ConvertTo-ModuleService
#>
[OutputType([Object])]
param(
# The name of the setting
[Parameter(Mandatory=$true,Position=0,ValueFromPipelineByPropertyName=$true,ValueFromPipeline=$true)]
[Alias('Name')]
[string]$Setting
)
process {
#region Load Config Store
# If the $request variable and Path_Info variable are found, use the nearby web.config
if ($Request -and $request.Params -and $request.Params['Path_Info']) {
$path ="$((Split-Path $request['Path_Info']))"
$webConfigStore = [Web.Configuration.WebConfigurationManager]::OpenWebConfiguration($path)
} else {
# Otherwise, try the one at the local path
try {
$webConfigStore = [Web.Configuration.WebConfigurationManager]::OpenWebConfiguration($pwd)
} catch {
}
}
#endregion Load Config Store
if (-not $webConfigStore) { return}
#region Get the custom setting
$customSetting = $webConfigStore.AppSettings.Settings["$Setting"];
# If there is a value, return it.
if ($CustomSetting) {
$CustomSetting.Value
}
#endregion Get the custom setting
}
}