Powershell Double $$ in Variable - Using .replace -


we have script generates random passwords , utilize function read password list various tasks. while using these passwords passed variable let's call $password. so,

$password = findpassword "blah"

if print $password return say, q@48$$!y@&$^

the issue this, when replace word in file using $password missing 1 of $ so, q@48$!y@&$^

here code using replace,

(get-content $some_file) |     foreach-object {$_ -replace "password","${password}"} | set-content $some_file 

anyone know of way show 2 $$ in row? have tried using ensure special characters treated appropriately, can't $ work:

$password = $password.replace("`^","`^") $password = $password.replace("`@","`@") $password = $password.replace("`&","`&") $password = $password.replace("`!","`!") $password = $password.replace("\`$","\`$") 

also,

$password = $password.replace("`$","``$") 

will work, if password different next time around, unique particular example.

if replace -replace operator .replace() method, trick:

(get-content $some_file) |     foreach-object { $_.tostring().replace("password", $password.tostring()) } | set-content $some_file 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -