2016-08-23 96 views
1

這是PowerShell腳本我工作的一部分:使用變量在命令

Write-Host $configJson.myVal 
(Get-Content .\config.js) -replace "S=''", "S='$configJson.myVal';" | Set-Content .\out.js 

Write-Host部分正確顯示在$configJson.myVal值。

但是當我運行第二個聲明,即把文件中的值是:System.Collections.Generic.Dictionary'2[System.String,System.Object].deployedBaseUrl

如何更改第二個命令,這樣即在Write-Host線路輸出值也投入我的替換命令文件?

回答

1

我會用一個格式字符串:

Write-Host $configJson.myVal 
(Get-Content .\config.js) -replace "S=''", ("S='{0}';" -f $configJson.myVal) | Set-Content .\out.js 
+0

那偉大的工作。我對PowerShell沒有經驗,我不知道這個選項。 – Vaccano

+0

Upps,忘了大括號...感謝您的編輯。 –

+1

沒問題。感謝您的正確方向。 – Vaccano