Get-Content -path $str | foreach {$_ -replace ............
i've been playing these few lines of script while no success.
i believe issue in syntax of directory paths trying replace. can point me in right direction.
script @ bottom self explanatory in case - want able change directory path of default queue database in exchange 2010. script reads line line content of config file looking $current , should replace $new.
any appreciated.
nick
i following error on execution:
invalid regular expression pattern: d:\sw\exch14\transportroles\data\queue.
@ d:\buildscripts\setqueuedb.ps1:14 char:32
+ $content | foreach {$_ -replace <<<< "$current", "$new"} | set-content $str
+ categoryinfo : invalidoperation: (d:\sw\exch14\transportroles\data\queue:string) [], runtimeexception
+ fullyqualifiederrorid : invalidregularexpression
####################################
#change location of queue database #
####################################
#sets queue directory path
$exchangeinstallpath = "d:\sw\exch14\"
$file = $exchangeinstallpath+"bin\edgetransport.exe.config"
foreach ($str in $file)
{
$content = get-content -path $str
$current = 'd:\sw\exch14\transportroles\data\queue'
$new = 'e:\exch14\transportroles\queue\database'
$content | foreach {$_ -replace "$current", "$new"} | set-content $str
}
the test pattern in -replace regular expression. characters in regex reserved, , need escaped if want them used literally. fortunately there's easy way this:
$content | foreach {$_ -replace [regex]::escape($current), $new} | set-content $str
will create regular expression $current reserved characters escaped you.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Windows Server > Windows PowerShell
Comments
Post a Comment