Solved

Powershell and Quoting rules

Posted on 2013-05-14
1
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
A procedure for exporting installed hotfix details of remote computers using powershell
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

705 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