header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
use robocopy in powershell and compress the file logs
Last Post 23 Apr 2009 11:05 AM by edm365f31. 4 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
edm365f31User is Offline
Basic Member
Basic Member
Posts:100
Avatar

--
23 Apr 2009 06:01 AM
    Is there a way to robocopy files and compress it in powershell?
    EBGreenUser is Offline
    Veteran Member
    Veteran Member
    Posts:1092
    Avatar

    --
    23 Apr 2009 06:34 AM
    "and compress it"

    Compress what? To use Robocopy in powershell, you just call it. Pretty much just like you would in cmd.exe or a bat file. Variables work a little different if you need to use those in the command line of course, but you call the exe pretty much the same way.
    "Look Ma...no strings!"
    edm365f31User is Offline
    Basic Member
    Basic Member
    Posts:100
    Avatar

    --
    23 Apr 2009 07:38 AM
    robocopy does not have a native way of zipping files, Resource kit has compact and compress, I basically need to zip a log and copy it to a remote share, I want to do all of this in PS.

    this is the way I run robocopy now: this is not getting zipped big logs 300 MB or more if I can zip this it will trim it down to 35 MB

    C:\Program Files\Windows Resource Kits\Tools\robocopy.exe C:\log\box\ \\box\\ /E /V /TS /X /NP /LOG+:"C:\logs\SOT.FileTransfer2.log" /TEE /ZB /R:10 /W:30
    EBGreenUser is Offline
    Veteran Member
    Veteran Member
    Posts:1092
    Avatar

    --
    23 Apr 2009 09:28 AM
    You can get the Powershell Community extensions. They add zip support to powershell. Or you can get the .NetZip library and access it from PS.
    "Look Ma...no strings!"
    edm365f31User is Offline
    Basic Member
    Basic Member
    Posts:100
    Avatar

    --
    23 Apr 2009 11:05 AM
    Thanks EB I got this script from Monad Out-zip Function, added some variables, still trying to figure out on how to zip a folder with files on it (file by file) not whole folder to a zip file. This out-zip function eliminate my use for Robocopy still not sure if it will be reliable.

    So is there a way to add a logic here to zip the file to a file?

    Maybe with the GCI function with a recurse?

    Thanks
    *************************************************************************************

    $path = $args[0]
    $files = $input
    $yesterday = ((get-date).adddays(-1)).tostring('yyyyMMdd')
    function out-zip {
    Param([string]$path)

    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)
    $input | foreach {$zipfile.CopyHere($_.fullname)}
    }

    gi $path | out-zip \\Study\ZipFiles\$yesterday.zip $_
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer