Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

replacing file path

$
0
0

Hi,

 

I am new to PowerShell.

I have a .confi (XML) file in UTF-16 unicode with over 100 lines. I need to find replace the some tags where file path is incorrect. 

 

I am able to find the file path store it in a variable. here is sample code i have: (Lets say the value in the $tempFolder = C:\Temp

 

$TempFolder = '($XML.configuration.appSettings.add) | Select-Object -Property Key,Value | Where-Object -FilterScript {$_.Key -eq "TempFolder"}'

$TempFolder_Newvalue = "L:\temp\"

(Get-Content $OrgConfigFile) | Foreach-Object {$_ -replace $TempFolder.value, $TempFolder_Newvalue ` } |  Set-Content -Path $ModConfigFile -Encoding Unicode 

 

i get following error:

Regular expression pattern is not valid: C:\temp\.

At C:\MyScripts\File_v2.ps1:67 char:9

+         $_ -replace $dbname, $dbname_Newvalue `

+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (C:\temp\:String) [], RuntimeException

    + FullyQualifiedErrorId : InvalidRegularExpression

 

If i manually change the $tempfolder value to ""C:\\temp\\" then it works but i am grabbing that information using different command and from an xml formated file and that value may not be c:\temp it could be diffrent path. Please advice how i can over come this problem

 

Thank you,

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles