Vaccano
Vaccano

Reputation: 82291

Use a variable in a command

This is part of the PowerShell script I am working on:

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

The Write-Host part correctly displays the value in $configJson.myVal.

But when I run the second statement, the value that is put in the file is: System.Collections.Generic.Dictionary'2[System.String,System.Object].deployedBaseUrl

How can I change the second command so that the value that is output on the Write-Host line is also put into the file for my replace command?

Upvotes: 1

Views: 40

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58931

I would use a format string:

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

Upvotes: 1

Related Questions