2013-08-26 63 views
-1

Iwant更新這兩個領域(客戶端和環境)通過使用正則表達式腳本功能更換特定領域使用PowerShell

<authentication mode="Forms"> 
    <forms name="AIR.client.environment.value" loginUrl="Login.aspx" protection="All" timeout="30" /> 
</authentication> 

的功能,我有

$regex_clientname = new-object System.Text.RegularExpressions.Regex("client=.*", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase); 
$regex_enviorenment = new-object System.Text.RegularExpressions.Regex("environment=.*", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase); 

$root.SelectSingleNode("//authentication/forms/@name")."#text"=$regex_enviorenment.Replace($regex_clientname.Replace($root.SelectSingleNode("//authentication/forms/@name")."#text", $CLIENT),$ENV); 

,但它沒有更新..我需要幫助

+0

我仍然沒有看到C++的任何相關性! –

回答

0

嗯,不知道你的閱讀在XML但如何試試這個:

$nodes = $root | Select-Xml '//authentication/forms/@name' 
$nodes | Foreach { $_.Node.Value = ($_.Node.Value -replace '(.*?)client(.*)',"`$1${CLIENT}`$2") -replace '(.*?)environment(.*)',"`$1${ENV}`$2"} 
$root.Save('path') 

請注意,要保留XML文件更改,您需要在xml文檔對象上調用Save()

+0

$ CLIENT和$ ENV是輸入變量。但我不知道如何將腳本轉換爲地雷。 – user2708556