Many of us might be/have been asked a similar question:
And the answer is…
🙂 So, intentionally my colleague asked me to write that under PowerShell 2.0 – to use zipping assembly we need to change/create PawerShell.exe.config file, here is well described what needs to be done:
Otherwise we will get following error in the PS console:
Add-Type : Could not load file or assembly ‘Drive_Or_ShareName\Path\To\The\System.IO.Compression.FileSystem.dll’ or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
So remedy for that is simply create/change PowerShell.exe.config, for me I needed to create it (was not there) with content like below:
Like even the script name implies – the script is very simply. It checks source directory (specified under Search_Folder parameter) for any files older than given period in days (Age_Of_Backuped_Data param). It moves all found files to the staging folder (Staging_Folder param), creates zip file in destination folder (Destination_Folder param), ensures that zip has been created and clears the staging area. All operations are being logged (LogFile param).
Few words about the script itself:
EasyPeasyZippingScript.ps1 – Easy script zipping files.
Easy script for wrapping files into the archive older than given period, deleting them from the source folder and saving the .zip file into the destination folder.
Output is the .zip file with name that is set by current date/time.
.\EasyPeasyZippingScript.ps1 -Age_Of_Backuped_Data 90 -Search_Folder D:\Search_here -Destination_Folder D:\Archives_here -Staging_Folder D:\Staging_here -LogFile logfile.log
In the above example EasyPeasyZippingScript.ps1 script moves items from “D:\Search_here” with creation date older than 90 days to the “D:\Staging_here” staging folder, zips that staging folder. Moves archive to “D:\Archives_here” and clears the “D:\Staging_here” folder. Also logs everything to the logfile.log file.
Have fun with IT!