49 lines
1.8 KiB
PowerShell
49 lines
1.8 KiB
PowerShell
function Get-MachineConfigAppSetting {
|
|
<#
|
|
.SYNOPSIS
|
|
Returns an app setting value from the machine config
|
|
#>
|
|
param (
|
|
[Parameter(Position = 0, Mandatory = $true)]
|
|
[Alias("Key")]
|
|
[string]$appSettingKey
|
|
)
|
|
|
|
Write-Warning "This function to be deprecated in favor of Get-AppSetting"
|
|
try {
|
|
Write-Host "##teamcity[message text='Found usage of Get-MachineConfigAppSetting. This should be switched to Get-AppSetting. Please address in $(Get-ParentExecutionName)' status='WARNING']"
|
|
} catch {
|
|
## In case the Get-ParentExecutionName call blows up. It shouldn't.
|
|
## But I'm calling this to deprecate the usage of this function, so I don't want this to break that ... yet
|
|
Write-Host "##teamcity[message text='Found usage of Get-MachineConfigAppSetting. This should be switched to Get-AppSetting. Please address in the parent call.' status='WARNING']"
|
|
}
|
|
|
|
$logLead = (Get-LogLeadName);
|
|
|
|
Write-Verbose ("$logLead : Reading machine.config")
|
|
$machineConfig = Read-MachineConfig
|
|
|
|
if ($null -eq $machineConfig) {
|
|
Write-Warning ("$logLead : The machine.config file could not be read")
|
|
return $null
|
|
}
|
|
|
|
$appSettingsNode = $machineConfig.Configuration.appSettings
|
|
|
|
if ($null -eq $appSettingsNode) {
|
|
Write-Warning ("$logLead : The app settings section could not be found")
|
|
return $null
|
|
}
|
|
|
|
Write-Verbose ("$logLead : Looking for AppSetting with Key {0}" -f $appSettingKey)
|
|
$appSetting = $appSettingsNode.SelectNodes("//add[@key='$appSettingKey']")
|
|
|
|
if (($null -eq $appSetting) -or ($appSetting.Count -eq 0)) {
|
|
Write-Warning ("$logLead : The AppSetting with Key {0} could not be found" -f $appSettingKey)
|
|
return $null
|
|
}
|
|
|
|
return $appSetting
|
|
}
|
|
|