I installed Powershell 1.0 onto the Windows Storage Server 2003 that has all the BAK files sync to it from source. Then my script goes through and creates a ZIP file of every BAK file. The author of the script above also wrote a quick script to delete all the BAK files once I was done.
Here is a run down of the script:
get-childitem -recurse |
where { $_.extension -match "bak" -and -not (test-path ($_.fullname -replace "bak", "zip")) } |
foreach { C:\7zip\7z.exe a ($_.fullname -replace "bak", "zip") $_.fullname }
get-childitem -recurse |
where { $_.extension -match "bak" -and (test-path ($_.fullname -replace "bak", "zip")) } |
foreach { del $_.fullname }
I choose a small font so the you can see the whole line as it would be in the script. Please keep in mind line breaks vs word wrap.
So here is what its doing:
- Give me all the files in the current directory recursively
- Filter out the files names that end in BAK that dont have a ZIP as well. ei: If File1.bak doesnt have a File1.zip, Grab it.
- Take the BAK file I just grabbed and ZIP it.
The second part of the script does the same thing as above with two minor changes:
- Grab files that DO have the same name as ZIP
- Then delete the Grabbed file.
While this script has been modified from its original, this is not my work. Credit goes to http://sradack.blogspot.com
THANKS SRADACK!!!
No comments:
Post a Comment