I'm trying up update a URL in an XML file with the value of an array.
I'm outputting the computer name to a text file. I need to read that text file and input the contents into a string in an XML file.
Code:
$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"
The issue I have is it's inputting the word $name
into the string instead of the value.
I've tried:
$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 errors with "unexpected token".
I've also tried:
$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 errors with "missing expression after ','".
I'm pretty sure that I'm not escaping the array correctly so that it knows its an array and not just a value.