Learn about Windows PowerShell
Summary: Learn how to use Windows PowerShell to easily create a zip archive.
How can I use Windows PowerShell to create a zip archive of a folder on my system?
Use Get-ChildItem from PSCX to copy the files, and pipe the output to the Write-Zip cmdlet:
Get-Childitem c:\fso -Recurse | Write-Zip -IncludeEmptyDirectories -OutputPath C:\fso_bu\fso.zip
Note: I have written several blog posts about the Windows PowerShell Community Extension Project. For more information about obtaining the PSCX module, see these Hey, Scripting Guy! Blog posts.
Is it worth using 7zip command line utility for better compression vs doing it this way?
@The DuderThe immediate advantage to this solution over 7zip isn't so much for better compression but that you leverage a tool native to the Server (PowerShell) to achieve the same task.You can even do some cool things like produce an RTF document using Windows PowerShell without having to Install Microsoft Word on a Server.SeanWindows PowerShell MVP
So i am using pscx and the command write-bzip2 it creates a Progress bar that doesn't goes away. Is there a way to clean that up?
Except that PSCX isn't "native". If you can distribute other files across the system with your script, you can just as easily bundle 7zip's command line tool.
I would say there's no advantage, personally. I use 7zip's command line for build automation on a number of projects, and I've been very satisfied. If the ability to generate files that can be unzipped anywhere is a concern, there's no reason 7zip can't generate
a plain zip file for you. That said, if PowerShell includes a simple command to zip files in the base PowerShell, I'll probably stop using 7zip to avoid the extra file distribution even if the compression would have been better. (Disk space is cheap and network
bandwidth is plentiful enough that the difference probably won't matter. My time dealing with those extra files isn't.)
The term 'Write-Zip' is not recognized as the name of a cmdlet
write-zip comes from the PS Community extensions PSCX