We currently have a script that generates random passwords and we utilize another function to read from this password list for various tasks. While using these passwords they are passed into a variable let's call $password
. So,
$password = FindPassword "blah"
If I were to print $password
then it would return say, Q@48$$!y@&$^
The issue with this, is when I replace a word in a file using $password
it is missing one of the $
so, Q@48$!y@&$^
Here is the code I am using for the replace,
(Get-Content $Some_File) |
Foreach-Object {$_ -replace "PASSWORD","${Password}"} | Set-Content $Some_File
Anyone know of a way to show two $$ in a row? I have tried using something like this to ensure special characters are treated appropriately, but can't get the $ to work:
$password = $password.Replace("`^","`^")
$password = $password.Replace("`@","`@")
$password = $password.Replace("`&","`&")
$password = $password.Replace("`!","`!")
$password = $password.Replace("\`$","\`$")
Also,
$password = $password.Replace("`$","``$")
Will work, but if the password is different the next time around, it is only unique to this particular example.