Wednesday, April 16, 2008

How to backup all your documents with 2 lines of PowerShell script

I (and I think all of us) have documents scattered every where in data drive.

Today I wanted to get all the word documents on my D: drive and put them on a shared folder for archiving.

Since I was playing with PowerShell recently, I thought it will be nice to write a script that do that, and the following is what I have written:

$files = Get-ChildItem -recurse -filter "*.doc*"
$files | foreach {copy $_.fullname -Destination E:\Docs}

I saved those 2 lines into a file [backup-docs.ps1] and opened PowerShell and navigate to my drive and called this script,and in seconds I found all my documents in the E:\Docs folder ; Thanks to PowerShell


1 comment:

Anonymous said...

Essam,
nice tip please post it at
Community-Submitted Scripts Center
http://www.microsoft.com/technet/scriptcenter/csc/tips/default.mspx

keep it up man :)