I am having trouble performing a simple string replacement operation.
I am building a function where the user is prompted to compare two directories. One is a Master ‘Source’ directory and the other is a ‘Target’ directory that could be located on a different server or multiple different servers.
I need to iterate through and change the path of the Source Directory to add the server path to the string to then perform the comparison operation.
As an example, I have three variables and then a ‘replace’ method used to replace one string for another.
$SourceFile = "C:\utlity\BCTest\test.txt" $SourcePath = "C:\utility\BCTest\" $TargetServerPath = "\\w16-dc2\c$\utility\BCTest\" $SourceFile.replace($SourcePath, $TargetServerPath)
My end result, I want the $SourcePath to be to be substituted with the $TargetServerPath variable, but retaining any subfolders and file names beyond that. I am expecting the output to look like this:
However, when I run this, the output is still the original $SourceFile path
Not sure what I am missing.