Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
General PowerShell
use robocopy in powershell and compress the file logs
Last Post 23 Apr 2009 11:05 AM by
edm365f31
. 4 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
edm365f31
Basic Member
Posts:100
23 Apr 2009 06:01 AM
Is there a way to robocopy files and compress it in powershell?
EBGreen
Veteran Member
Posts:1092
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!"
edm365f31
Basic Member
Posts:100
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
EBGreen
Veteran Member
Posts:1092
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!"
edm365f31
Basic Member
Posts:100
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.
Using PowerShell
--General PowerShell
--Active Directory
--Exchange Server
--Lync Server
--SharePoint
--SQL Server
--System Center
--Non-Microsoft Products
--Books, Tools, and Videos
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
General PowerShell
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2