I have a process in place where another department recieves faxes and then copies those faxes into a fileshare that my dept. manages. On our side of things we consider this share as the "Source" we then have a need of copying these files to another share that is monitored by an application that imports the files into a Document Management System which I refer to as the "Destination".
Currently there is a VBS script that MOVES these files while renaming them. The rename appends text to the beginning of the file name, but leaves the rest of the name alone. For instance if the file name is abc123.pdf ... after the move/rename the file name might be "Marketing-abc123.pdf"
The changed file name shows up in the DMS so that users of the various departments can find their stuff quickly and do what they need to with the files.
The issue I have is that the VBS script ... which I don't really understand, moves these files to one single location.
I want to do this with Powershell, but I can't seem to figure out how to append specified text to the file name, yet leave the rest of the file name alone.
The reason I wish to convert this process to powershell is not only do I have a better understanding of it than VBS, but I want to direct the orginal file to 2 locations (for backup purposes) and to generate a log file for a record of what occurred & when.
So I need to append text to a file name. Copy the file to a new location, then MOVE the file to a backup location. I don't want the code to proceed to delete if it fails to copy which is why I state Move.
There are several processes like this in place. One of which doesn't require the appending of text to the file name and the code I am using for that is as follows, I was hoping to modify it to do what I want:
$Source = "\\SourceServer\Share" $Destination = "\\DestinationServer\Share" $Bkp = "\\BackupServer\Share" if(Test-Path -Path $Source\* -include *.pdf) { Add-Content -Path $Source\copy.log -value "**********BEGIN ACTION @ $time**********" Copy-Item -path $Source\* -include *.pdf -destination $Bkp -passthru | format-table -property LastWriteTime,Name -autosize | out-file $Source\copy.log -Append -Encoding ascii Move-Item -path $Source\*.pdf -destination $Destination Add-Content -Path $Source\copy.log -value "**********STOP ACTION @ $time**********`r`n================================================`r`n" Copy-Item $Source\copy.log $Bkp\copy.log } ELSE { Add-Content -Path $Source\copy.log -value "**********BEGIN ACTION @ $time*********`r`n`r`n0 Files Copied`r`n`r`n**********STOP ACTION @ $time**********`r`n================================================`r`n" }