ps/Modules/Alkami.PowerShell.Common/Public/Set-XmlNodeValue.ps1
2023-05-30 22:51:22 -07:00

37 lines
977 B
PowerShell

function Set-XmlNodeValue {
<#
.SYNOPSIS
Set web.config node. Depend on Set-AlkamiConfigs
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][Xml]$doc,
[string]$NodeString,
[String]$AttributeName,
[String]$AttributeValue
)
$logLead = (Get-LogLeadName);
$matchingNodes = $doc.SelectNodes($NodeString)
if ($null -eq $matchingNodes -or $matchingNodes.Count -eq 0)
{
Write-Warning ("$logLead : Could not find node {0} in the supplied XML" -f $NodeString)
}
elseif ($matchingNodes.GetAttribute($AttributeName) -eq $AttributeValue)
{
Write-Host "$logLead : Node already has correct value '$AttributeValue'"
$changed = $false
}
else
{
Write-Output ("$logLead : Updating Node '{0}' With Value '{1}'" -f $NodeString, $AttributeValue)
$matchingNodes.SetAttribute($AttributeName,$AttributeValue)
$changed = $true
}
Return $changed
}