take it:
function Out-ZIP ([string]$archive) {
Process {
# get current date and time in specified format
$datex = get-date -Format dd.MM.yy_hh.mm
# create archive file name structure that includes
# folder name, date/time and .zip extension
$name = $archive + "$_.name" + $datex + '.zip'
# if not exist, make new ZIP file
if (-not (test-path $name)) {
set-content $name ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
}
# create COM object and set to it archive name
$ZipFile = (new-object -com shell.application).NameSpace($name)
# receive from pipeline each folder object and compress it
$_ | % {$zipfile.CopyHere($_.fullname)}
}
End {
# set how much archives will be stored. Here is 10 days
$date = (Get-Date).AddDays(-10)
# check archive folder for archives that are older than
# $date days and remove them.
dir ($archive + "*.zip") | ?{$_.lastwritetime -le $date} | del -Force
}
}
I hope this helps you!
--
WBR, Vadims Podans
PowerShell blog -
www.sysadmins.lv
"David Sherman" <dshermin@xxxxxx> rakstīja ziņojumā
"news:cernr41iila0k4t69dc6u675s04cr9qbgl@xxxxxx"...
> On Sat, 14 Mar 2009 19:22:00 +0200, "Vadims Podans" <vpodans> wrote:
> Since I am not a programmer:
>
> how do I structure the file.
>
> # Part 1
>
> ########################################################
> #
> # out-zip.ps1
> #
> # Usage:
> #
> # To zip up some files:
> # ls c:\source\*.txt | out-zip c:\target\archive.zip $_
> #
> # To zip up a folder:
> # gi c:\source | out-zip c:\target\archive.zip $_
> ########################################################
>
> $path = $args[0]
> $files = $input
>
> if (-not $path.EndsWith('.zip')) {$path += '.zip'}
>
> if (-not (test-path $path)) {
> set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
> }
>
> $ZipFile = (new-object -com shell.application).NameSpace($path)
> $files | foreach {$zipfile.CopyHere($_.fullname)}
>
> # then
>
> $datex = get-date -f dd.MM.yy_hh.mm.
> $Outputfilename = $_.name + $datex + '.zip'
>
> # and then
>
> $numberofarchives = 10
> if ((dir c:\archives).count -gt $numberofarchives) {
> dir c:\archives | sort lastwritetime | select -first $(dir
> c:\archives).count - $numberofarchives) | del -force
> }
>
> and where do I place my folders?
>
> thanks