Click here to Skip to main content
15,886,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to avoid a key name value not getting updated while doing find and replace in powershell. I am able to find and replace filestore path in config file. But I do not want to replace the folder path for a key in the config file
Here I am replacing folder path with C: drive to a network path. But I don't want to replace the folder path for a key
ChartImageHandler in config file.
<pre><add key="ReconciliationFilePath" value="\C:PAYMENT_HUB\Filestore\FTS_FileStore\ISGREPORTS\" />
   
    <add key="ChartImageHandler" value="storage=file;timeout=20;dir=\C:PAYMENT_HUB\Filestore\FTS_FileStore\TempImageFiles\;" />


What I have tried:

Config path as below:
<pre><add key="ReconciliationFilePath" value="\C:PAYMENT_HUB\Filestore\FTS_FileStore\ISGREPORTS\" />
   
 
    <add key="ChartImageHandler" value="storage=file;timeout=20;dir=\C:PAYMENT_HUB\Filestore\FTS_FileStore\TempImageFiles\;" />


Script is as below:
#UAEWPS Application if ($Line -notmatch '\#')
$Application_Path="C:\PAYMENT_HUB\UAEFTS\Web.Config"
$Application_Path

foreach ($Line in $ConfigFile) {
    if ($Line -notmatch 'ChartImageHandler') {
    (Get-Content $Application_Path) | 
     Foreach-Object {$_.replace("C:\", "\\10.40.0.137\")} | 
     Set-Content $Application_Path	
}
}
Posted
Comments
Tomas Takac 28-Apr-20 2:40am    
If those are XML files, you can read them as such and only do the replace in values and not keys.
Sinisa Hajnal 29-Apr-20 6:06am    
Also, you already know which line you're replacing, don't do foreach, just replace that single line

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900