0
我在尝试使用数组的值更新XML文件中的URL。数组的输出值到文件中的字符串
我将计算机名输出到文本文件。我需要读取该文本文件并将内容输入到XML文件中的字符串中。
代码:
$name = Get-Content 'C:\temp\hostname.txt'
(Get-Content "E:\Source\Igloo Upgrade to v5.0\Igloo Enterprise Distribution 5.0\Setup\Igloo Enterprise Administrator.SetParameters.xml") |
ForEach-Object {$_ -replace '//twscheduler/','//$name/'} |
Set-Content "E:\Source\Igloo Upgrade to v5.0\Igloo Enterprise Distribution 5.0\Setup\Igloo Enterprise Administrator.SetParameters.xml"
我的问题是它的输入字$name
到字符串,而不是价值。
我已经试过:
$name = Get-Content 'C:\temp\hostname.txt'
(Get-Content "E:\Source\Igloo Upgrade to v5.0\Igloo Enterprise Distribution 5.0\Setup\Igloo Enterprise Administrator.SetParameters.xml") |
ForEach-Object {$_ -replace '//twscheduler/','//'$name'/'} |
Set-Content "E:\Source\Igloo Upgrade to v5.0\Igloo Enterprise Distribution 5.0\Setup\Igloo Enterprise Administrator.SetParameters.xml"
这个错误有 “意外的标记”。
我也试过:
$name = Get-Content 'C:\temp\hostname.txt'
(Get-Content "E:\Source\Igloo Upgrade to v5.0\Igloo Enterprise Distribution 5.0\Setup\Igloo Enterprise Administrator.SetParameters.xml") |
ForEach-Object {$_ -replace '//twscheduler/',//$name/} |
Set-Content "E:\Source\Igloo Upgrade to v5.0\Igloo Enterprise Distribution 5.0\Setup\Igloo Enterprise Administrator.SetParameters.xml"
这种错误与 “后失踪表达 ''”。
我很确定我没有正确地转义数组,所以它知道它的数组而不仅仅是一个值。
PERFECT!非常感谢你。工作完美无瑕! –
对不起,现在就完成了。再次感谢理查德 –