Я пытаюсь обновить URL-адрес в XML-файле со значением массива.Выходное значение массива в строку в файле
Я выводил имя компьютера в текстовый файл. Мне нужно прочитать этот текстовый файл и ввести содержимое в строку в файле 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"
This ошибки с "неожиданной лексемы".
Я также попытался:
$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"
This ошибки с "отсутствует выражение после ''".
Я уверен, что я не избегаю массива правильно, чтобы он знал свой массив, а не просто значение.
PERFECT !! Большое спасибо. Работал безупречно! –
Простите, теперь. Еще раз спасибо Ричард –