• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Powershell and Quoting rules

I need to pass a variable into the following command, but I can't get it to work:

Get-Content E:\web.config ) | ForEach-Object {$_ -replace '<add key="DataSource" value="TEST_xxx" />', '<add key="DataSource" value="TEST_$num" />'} | Set-Content E:\web.config

Open in new window


$num is defined as LOT1

Any ideas ?
0
ndr-itsolutions
Asked:
ndr-itsolutions
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
cls
$num = "LOT1"
$data = [IO.File]::ReadAllText("E:\web.config")
$data -replace '<add key="DataSource" value="TEST_xxx" />', ('<add key="DataSource" value="TEST_{0}" />' -f $num) | Out-File E:\web.config

Open in new window

0

Featured Post

What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now