Solved

Powershell and Quoting rules

Posted on 2013-05-14
1
251 Views
Last Modified: 2013-05-14
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
Comment
Question by:ndr-itsolutions
1 Comment
 
LVL 42

Accepted Solution

by:
sedgwick earned 400 total points
ID: 39164234
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question