-1

正規表現スクリプト関数を使用して、これら 2 つのフィールド (クライアントと環境) を更新したい

 <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);

しかし、それは更新されていません..私は助けが必要です

4

1 に答える 1

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')

Save()XML ファイルの変更を永続化するには、xml ドキュメント オブジェクトで呼び出す必要があることに注意してください。

于 2013-08-26T17:02:42.037 に答える