I am getting an "illegal characters in path" error with the following code. Any thoughts?
$source = \\md\drive\MMM\<<DriveEnv>>\AA\Extracts\Active\filename.csv
$newfilename = \\md\drive\MMM\<<DriveEnv>>\AA\Extracts\Active\filename.csv.TEMP
Rename-Item $source -NewName $newfilename 0 1 Answer
Find the illegal characters and use Replace to strip them out in PowerShell. Below is an example how to replace < and > characters with NULL values which basically removes those characters.
It also appears that the << and >> are not be valid characters for a folder name in a UNC path. So you might replace those with the valid location or give an example to further test what that is actually set to in your example.
$source = "\\md\drive\MMM\<<DriveEnv>>\AA\Extracts\Active\filename.csv"
$source = $source.Replace("<","")
$source = $source.Replace(">","")
$newfilename = $source
$newfilename = $newfilename + ".TEMP"
Rename-Item $source -NewName $newfilename 2