PowerTip: Use PowerShell to Create Zip Archive

Summary: Learn how to use Windows PowerShell to easily create a zip archive.

Hey, Scripting Guy! Question How can I use Windows PowerShell to create a zip archive of a folder on my system?

Hey, Scripting Guy! Answer 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.

Comments (7)

  1. The Duder says:

    Is it worth using 7zip command line utility for better compression vs doing it this way?

  2. mredwilson says:

    write-zip comes from the PS Community extensions PSCX

  3. @The Duder
    The 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.

    Windows PowerShell MVP

  4. powershell_user says:

    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?

  5. Anonymous says:

    @Sean Kearney
    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.
    @The Duder
    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.)

  6. Mark says:

    The term ‘Write-Zip’ is not recognized as the name of a cmdlet

Skip to main content