<# 2/7/2015 - Jen McCown MidnightSQL Consulting, LLC http://www.MidnightSQL.com Reference: http://www.midnightdba.com/Jen/?p=5064 WARNING: This script is presented WITHOUT any kind of warranty, and is all your responsibility. Also, watch your output for errors. And if you run out of room, not everything will copy (duh). Run Robocopy to copy files to an external HD or other offsite location. *** SETUP *** Edit the path in $SRC and $DEST If you just want to see the robocopy scripts without running, set $myWhatIf to 1 Edit this line to exclude folders: IF ($_ -ne 'XYZ' -and $_ -ne 'temp' ) *** ABOUT *** This is what the script does: 1. Get the list of drives to copy from $SRC (minus any ones we don't want). For each folder and file in $src: 2. write-output that you're doing it 3. Create that drive in $DEST 4. Create and run the robocopy statement for it 5. then a complete notice. #> <### 1. Get the list of drives to copy from $SRC (minus any ones we don't want). ###> $SRC = 'c:\MyBaseFolder'; #!! Don't end this with a slash $DEST = 'E:\MyComputerbackup'; #!! Don't end this with a slash either $myWhatIf = 1 #!! If you just want to see the robocopy scripts without running, set this to 1 # Error checking IF ((test-path "$src") -eq $FALSE) { Write-Output "ERROR: Source path does not exist: $dest" } IF ((test-path "$dest") -eq $FALSE) { Write-Output "ERROR: Destination path does not exist: $dest" } <### For each folder and file in $src: ###> $items = DIR $src; $items | % { IF ($_ -ne 'XYZ' -and $_ -ne 'temp' ) #!! Edit this line with as many exclusions as you like { <### 2. write-output that you're doing it ###> write-output "" write-output "**************** COPYING '$src\$_' to '$dest\$_' ****************" <### 3. Create that drive in $DEST ###> IF ((test-path "$dest\$_") -eq $FALSE -and $myWhatIf -eq 0) { write-output "creating $dest\$_"; mkdir "$dest\$_"; } IF ($myWhatIf -eq 1) { write-output "mkdir '$dest\$_';" } <### 4. Create and run the robocopy statement for it ###> IF ($myWhatIf -eq 0) { write-output "ROBOCOPY /S /R:0 '$src\$_' '$dest\$_'" ROBOCOPY /S /R:0 "$src\$_" "$dest\$_" } ELSE { write-output "ROBOCOPY /S /R:0 '$src\$_' '$dest\$_'" } } ### END OF IF -ne 'bendycon'.. } <### 5. then a complete notice. ###> write-output "" write-output "***********************************************" write-output "**************** COPY COMPLETE ****************" write-output "***********************************************"