Having a hard time troubleshooting this
$source = $args[0]
$dest = $args[1]
$fstr = $args[2]
$rstr = $args[3]
If(!(test-path $dest))
{
New-Item -ItemType Directory -Force -Path $dest | out-null
}
If((test-path $source))
{
$files = Get-ChildItem $source *.ICMS
ForEach ($file in $files)
{
$filePath = $source + "\" + $file;
$x = Get-Content $filePath
$x[0] = $x[0].Replace($fstr,$rstr)
$outfile = $dest + "\" + $file.Name $x2 = $x[0..($x.Length-2)]
$x = $x2.ForEach({ $_ + "`n"})
$x | Set-Content -NoNewline $outfile
}
}
Else {"Source directory doesn't exist"}
I receive an error saying Unexpected token '$x2' in expression or statement