Automatic Zip and Backup a Folder

Tags: powershell, backup, zip

To backup folder C:\websites to c:\Backups using powershell from command prompt:

powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('c:\websites', 'c:\Backups\websites_' + $(get-date -f yyyy-MM-dd) + '.zip'); }"

You can put the above command in a .bat file and schedule it via Windows Task Scheduler.  Note that any existing file will not be overwritten and script will fail if output file already exists.  Hence the addition of a date suffix to .zip file name

1 Comment

  • verasearch3 said Reply

    see also: https://www.experts-exchange.com/questions/28414939/Add-Date-Time-to-powershell-exported-results-filename.html

You must log on to comment.