I use powershell -replace
command to update the data source in my configuration Attempting File However, the -replace
regex $ oldServer
will not remove the value below
I have a string in the Edit For the comment below I have a metadata = rijs // /MonetDb.csdl|res:// / MonetDb .ssdl .res: // www / MonetDb MSL; Provider = System.Data.SqlClient; Provider connection string = "data source = quasq10 \ sql08a, initial list = mydb; integrated security = true; multipleactiveresultsets = true; application = EntityFramework" $ _ ConnectionString is stored in the variable and it has been saved properly, so I know that this is not a problem. Only seems to be regex
#environment variable $ env = "dev" $ oldServer = "quasq10" $ newValue = "$ env-AR-SQL.CORP.COM" $ doc = [XML ] (Get-content "D: \ AMS \ app.config") $ doc.configuration.connectionStrings.add |% {$ _. ConnectionString = $ _ Change ConnectionString- $ oldplace, $ newValue; } $ Doc.Save ($ file.FullName)
write-host Added $ _. ConnectionString
statement is the console output as the first line in the loop
I just put it in the correct ISE, I copied my connection string into one variable and was able to convert it to a closed form.
$ connectionstring = 'metadata = race: ///MonetDb.csdl | Race: ///MonetDb.ssdl | Race: //*/MonetDb.msl; Provider = System.Data .SqlClient; Provider Connection String = "Data Source = Quasq10 \ sql08a, Initial List = mydb; Integrated Security = True; Multipleactiveresultsets = True; Application = EntityFramework" '$ env = "Dev" $ oldServer = "quasq10" $ newValue = "$ env- AR-SQL.CORP.COM "$ connectionstring -replace $ oldServer, $ newValue
Race: ///MonetDb.csdl | Race: // initial list = mydb; Integrated Security Connection String = "Data Source = DEV-AR-SQL.CORP.COM \ sql08a /MonetDb.ssdl|res://*/MonetDb.msl;provider=System.Data.SqlClient;provider = True; Multiple Methodology = True; App = EntityFramework "
I think your foreach loop is not getting information about your information, because it seems that your place is OK.
$ doc.configuration.connectionStrings.add
I have not done much with XML, does the XML data type contain an ADD member function? You are not really adding anything, right?
As a test, what do you get from it:
$ doc.configuration.connectionStrings | % {$ _. ConnectionString- moved $ oldServer, $ newValue; }
Go against a dummy file and see what happens.
$ string = "Quick brown fox to jump on a celestial dog" $ old color = "brown" $ new collar = "Orange" $ string- moved $ old color, $ newColor
This method works to avoid digging through comments
$ String.Replace ($ oldColor, $ newColor)
No comments:
Post a Comment