I have an application that has a bat file which can be ran which exports the configuration of the application to a directory named conf-exported. When it is ran, it creates a subdirectory in conf-exported named with a date time stamp format. For example, YYYYMMDDHHMMSS. I can automated the batch file to run daily in order to have the application configuration backed up daily. What I would like to do is move the subdirectory to another server. A copy is not good because the configuration contains encrypted credentials which may not work if I try to use the configuration on another server.
Is there a simple way to do this in Powershell and create and update a log each time the subdirectory has been moved. Please advise. Thank you.
Move-Item is the cmdlet you want to use.
I think I may be able to use ROBOCOPY instead. I will test and see. Thanks.
Well, you indeed should use RoboCopy for this but not because that’s easier and you are a beginner at Powershell.
It’s just the right tool for the job. You could create a BAT file with something that looks like this:
set tdate=%date: =%
set ttime=%ttime: =%
Robocopy \\ServerA\Folder1 \\ServerB\Folder1 /COPYALL /MOVE /R:2 /W:1 /log:c:\robocopy\AT_%tdate%-%ttime%_transferFiles.txt /v /tee /fp /eta
So this way, each job would have a unique filename that has the date on which it was executed.
You can lookup the parameters yourself (https://technet.microsoft.com/en-us/library/cc733145(v=ws.11).aspx),
these are the ones i use mostly. It adds some visibility when you run them manually. In the scope of the script, some aren’t as useful since you won’t ever look at it.
Moves files, and deletes them from the source after they are copied.
Moves files and directories, and deletes them from the source after they are copied.
Thank you. I try to open the link you provided, but it does not open for me.
thats because the extension fell of for some reason.