Atualize o configSource do elemento XML no web.config usando o Powershell passando em Parâmetros

Eu estou tentando descobrir uma maneira de atualizar meu web.config para diferentes ambientes, atualizando o configSource para o elemento appSettings no web.config.

Aqui está o jeito que eu sei fazer.

$xml.get_DocumentElement().appSettings.configSource = $replaced_test

O problema é que eu quero um script base onde eu possa passar nós diferentes para o script que eu quero mudar e atualizar, mas não tenho certeza de como fazê-lo.

Por exemplo, eu quero ser capaz de chamar um script de powershell como este

changeWebConfig.ps1 nodeToChange newValueofNode

Espero que isso tenha sido claro o suficiente.

Este é o código que tenho agora.

$webConfigPath = "C:\web.config"   

# Get the content of the config file and cast it to XML 
$xml = [xml](get-content $webConfigPath) 

#this was the trick I had been looking for  
$root = $xml.get_DocumentElement()."system.serviceModel".client.configSource  = $replace

# Save it  
$xml.Save($webConfigPath)

O problema que eu estava tendo era o nó de configuração

Eu tive que mudar isso

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

isso para

<configuration>

Eu não sei como encontrar o nó com o nó de configuração em seu estado original ainda, mas estou chegando perto.

function Set-ConfigAppSetting
([string]$PathToConfig=$(throw 'Configuration file is required'),
         [string]$Key = $(throw 'No Key Specified'), 
         [string]$Value = $(throw 'No Value Specified'))
{
    if (Test-Path $PathToConfig)
    {
        $x = [xml] (type $PathToConfig)
        $node = $x.SelectSingleNode("//client[@configSource]")
        $node.configSource = $Value
        $x.Save($PathToConfig)
    }
} 

set-configappsetting "c:\web.config" CurrentTaxYear ".\private$\dinnernoworders" -confirm

questionAnswers(2)

yourAnswerToTheQuestion