Wednesday, June 5, 2013

Powershell command to backup / copy

Use this Powershell command to copy / backup files to remote filesystem.

Copy-Item "C:DIRECTORYTOCOPY*" "DESTINATIONDIR" -Recurse -Force | Out-Null

Change the DIRECTORYTOCOPY & DESTINATIONDIR to appropriate parameters.
- recurse option forces it to copy subfolders and contents
- force option tells it to create new folders in destination that are missing
out-null tells it to finish this line before moving on to the next line of code

Save as a .ps1 extension, then create a batch file to call the .ps1 file.  The batch file can be scheduled.