1

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?

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

That worked great. I am so inexperienced to PowerShell, I did not know about that option.
Upps, forgot the curly brackets... Thanks for the edit.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.