Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell find/replace in web.config not updating Password values

$
0
0

All,

I am trying to use a powershell to update values when moving code/configs from one environment to another (yes, I know it's hokey, but it is what it is).  I basically have the values I wanted changed held in a SQL table, assign them to an array and loop through the find and replace.  However it is not replacing any of the password values in my connections strings or <appSettings> <add Key..> tags.  It also won't update the username in the Identity tag, but will update the password in that tag only.  I am at a loss since it will update the majority of the text but not these two item types.  If I open the file with notepad and do a find/replace copying the values from my table, the values will change. I tried removing the array from the equation and just do a simple find replace. 

Example: I want this line in my web.config to update

<add key="ConnectSQLServerDB" value="Initial Catalog=ReportServer;Data Source=SQLServerName;UID=SQLUSERID;PWD=SQLPSWRD;" />     

The following Powershell will update:

(Get-Content $file.PSPath) |
Foreach-Object {$_ -replace 'SQLUSERID', 'SQLUSERIDQA'} |
Set-Content $file.PSPath

I can also update {$_ -replace 'SQLServerName', 'SQLServerNameQA'}. But when I change it to update SQLPSWRD (seen below) the value is not updated.

(Get-Content $file.PSPath) |
Foreach-Object {$_ -replace 'SQLPSWRD', 'SQLPSWRDQA'} |
Set-Content $file.PSPath

I even tried the entire string below, but it would not update.

(Get-Content $file.PSPath) |
Foreach-Object {$_ -replace 'Data Source=SQLServerName;UID=SQLUSERID;PWD=SQLPSWRD', 'Data Source=SQLServerNameQA;UID=SQLUSERIDQA;PWD=SQLPSWRDQA'} |
Set-Content $file.PSPath

Is there something protecting the passwords that I don't know about?  My script is ensuring the file is read-write.

Thanks for your time.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>