Solved

Powershell and Quoting rules

Posted on 2013-05-14
1
249 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now