Zip up a Folder with PowerShell 3 the Easy Way
Friday, August 17, 2012 at 10:05PM My previous post showed how to do this with C# and Visual Studio. Because PowerShell 3 in Windows 8 uses the .NET 4.5 CLR we can use the same technique to create a ZIP file without relying on external libraries or tools.
The script is straightforward. Just load the System.IO.Compression.FileSystem assembly and call[System.IO.Compression.ZipFile]::CreateFromDirectory().
[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )
$src_folder = "D:\stuff"
$destfile = "D:\stuff.zip"
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
$includebasedir = $false
[System.IO.Compression.ZipFile]::CreateFromDirectory($src_folder,$destfile,$compressionLevel, $includebasedir )
saveenr |
2 Comments |
Reader Comments (2)
Hi
Thanks for this post. Just a question about this: Are there any size limits of the zip file with this method?
Regards
@Marius - I haven't tried it with anything over 100MB - so I'm not sure what will happen if you try it with a many gigabytes of data.