Powershell - Get text into variable, use text to replace text in another text file
Anyone know how i can get this code to work?
#The following fetches the first word of the path of the Public folder to use to modify the string in the next command.
$PFNameString = Get-Content("H:\Temp\PublicFolder-powershell\Word_1_Export.csv")
$Option = [System.StringSplitOptions]::RemoveEmptyEntries
$Separator = "\"
$arr = $PFNameString.Split($Separator,$Option)
$Word = $arr[0] #This is the one word i want to use as replacement text to search for in text file loaded next.
$b = Get-Content -Path "H:\Temp\PublicFolder-powershell\PFPerm.02_YandU_correct_AccessRights.csv"
@(ForEach ($a in $b) {$a.Replace('",$Word', '"$Word')}) > "H:\Temp\PublicFolder-powershell\PFPerm.03_Qot_And_D_correct_AccessRights.csv"
I know how to get it to replace, but i want it to use the word in the $Word variable i extracted from the array imported from the first text file, as the "wildcard" to search for and replace with in the 2nd text file.
In this case the word is "Distrikt"
And i want the script to replace '",Distrikt' with '"Distrikt'

And if the variable text changed, the script would still use the variable text as wildcard to search for.
Thanks
EDIT: Result of working script afterwards:
########## This script first opens the file Word_1_Export.csv and split it into array segments.
######### Then the first word in the array is stored in the variable $Word to make the search function more selective
######## This script opens PFPerm.02_YandU_correct_AccessRights.csv and saves back to PFPerm.03_Qot_And_D_correct_AccessRights.csv after processing.
####### This code replace the first ",$Word in the line, with "$Word so the name will be valid for later processing.
###### This code replace the first ",$WORD" in the line with "$WORD" without comma.
##### The goal with this script is to replace the initial COMMA of the line, and saves back to the new file that can be later used.
#The following fetches the first word of the path of the Public folder to use to modify the string in the next command.
$PFNameString = Get-Content("H:\Temp\PublicFolder-powershell\Word_1_Export.csv") #Get text
$Option = [System.StringSplitOptions]::RemoveEmptyEntries
$Separator = "\" #Sign to use as separator of array segments
$arr = $PFNameString.Split($Separator,$Option) #Splits to array segments based on "\"
$Word = $arr[0] #Fetches the first array segment and stores it into the variable $Word
$b = Get-Content -Path "H:\Temp\PublicFolder-powershell\PFPerm.02_YandU_correct_AccessRights.csv" #Loads in the next text file.
#Special quotes under here is required for the Variable to be possible to access ("`",$Word", "`"$Word")}) - The special single quote here instead of "'" is needed.
#If you only had a static word to lookup, you could specify it with ('",StaticWord', '"StaticWord')}) and do the same, but it would not be dynamic as with this below line of code.
@(ForEach ($a in $b) {$a.Replace("`",$Word", "`"$Word")}) > "H:\Temp\PublicFolder-powershell\PFPerm.03_Qot_And_D_correct_AccessRights.csv"
Start-Sleep -Seconds 0.3 #grants time for script to save txt-files back.