I have text file which contains some keys of an hash table in the form of ${key}. I need to parse the text file and replace ${key} with it's value. Below is the code i am using
#$config is the hashtable
$document = Get-Content sample.txt
foreach ($conf in $config.Keys) {
[string]$match = '${' + $conf + '}'
$document = $document.Replace($match, $($config.$conf))
}
}
I have tried below alternatives for $match string
[string]$match = "`${" + $conf + "}"
[string]$match='${'
$match+=$conf
$match+='}'
I even tried hard coding the string as $match='${BACKUP_FOLDER}' but in all the cases it does nothing. I have also tried -match to see if something matches but it always returns false.
I have confirmed that the text file contains several patterns of ${key} format and if i copy the output of $match and search in the file i can find the patterns. Could you please point out what's wrong. I am using Powershell V5.0
Sample input
$config=@{"BACKUP_DIR"="_Backup";"STAGING_DIR"="_Staging"}
Contents of sample.txt
Overwrites the contents of new installation with old installation
Always use / as path seperator-->
<!-- <rename path="" newName=""/> -->
<!--
${BACKUP_DIR}
rename-> rename file/directory in new installation
Output: ${BACKUP_DIR} should be replaced with _Backup