换行符读取来自 XML 的输入

Line breaks reading input from XML

我正在创建一个脚本来在 2.6.5 中安装 Octopus Tentacles。要读取更改的值,我将它们从 XML 中提取到 PowerShell 脚本中。我一直 运行 解决 instanceName 正在创建换行符的问题。

因此:

Write-Output "$homePath$instanceName$instanceName.config"

我得到:

C:Apps\Octopus\Tentacle\

Test

\

Test.config

它在使用 instanceName 的地方换行。

这是我的 XML 和 PowerShell:

XML:

<OctopusEnviroment>
<Sxsport>
10933
</Sxsport>
<instanceName>
Test
</instanceName>
<sthumb>
3FD6D126A383A949262668B5D9E36F08A7699B748
</sthumb>

PowerShell:

$sxsportVar = ""
$instanceNameVar = ""
$sthumbVar = ""

[xml]$SiteAttribute = Get-Content OctopusEnv.xml


$sxsportVar = $SiteAttribute.OctopusEnviroment.Sxsport
$instanceNameVar = $SiteAttribute.OctopusEnviroment.instanceName
$sthumbVar = $SiteAttribute.OctopusEnviroment.sthumb

####Instance name the Tentacle will be registered to
$instanceName = $instanceNameVar
####Thumbprint from Deployment Server
$sthumb = $sthumbVar
####Port Tentacle is listening on
$sxsPort = $sxsportVar

我在这里没有看到问题,但你可能想删除换行符?

$SiteAttribute.OctopusEnviroment.instanceName -replace '\s'