Powershell - Compress-Archive and Expand-Archive to create and extract ZIP archives
To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker, purchase my 3D plans, or make a donation or subscribe on Ko-Fi. Thank you!
Windows Powershell, via the Microsoft.PowerShell.Archive module, allows us to create, update and extract ZIP archives.
The Compress-Archive command archive in ZIP format only, does not support files larger than 2GB and does not support hidden files.
Version 2 of the Microsoft.PowerShell.Archive module has obviously been abandoned :
https://github.com/PowerShell/Microsoft.PowerShell.Archive
# Compress a folder and its contents by specifying the compression level (NoCompression, Fastest, Optimal).# Optimal is the defaultCompress-Archive -Path c:\test -DestinationPath c:\test.zip -CompressionLevel Fastest
# Compress the contents of a folderCompress-Archive -Path c:\test\* -DestinationPath c:\test.zip
# Compress the contents of a folder and overwrite a previous archive (-Force)Compress-Archive -Path c:\test\* -DestinationPath c:\test.zip -Force
# Compress certain filesCompress-Archive -Path c:\test\doc1.txt,c:\test\*.docx -DestinationPath c:\test.zip
# Compress certain files using Get-ChildItem to filterGet-ChildItem -Path c:\test -file | Compress-Archive -DestinationPath c:\test.zip
# Update the contents of the archive (newer files replace older ones in the archive)Compress-Archive -Path c:\test -DestinationPath c:\test.zip -Update
# Uncompress an archive in a folder with the name of the archive in the current folderExpand-Archive -Path c:\test.zip
# Unzip an archive into a folder specifying the location (if the folder does not exist, it will be created)Expand-Archive -Path c:\test.zip -DestinationPath c:\test2
# Unzip an archive into a folder with the archive name in the current folder, overwriting existing filesExpand-Archive -Path c:\test.zip -Force
# Display the contents of an archive[System.IO.Compression.ZipFile]::OpenRead(‘c:\test.zip’).Entries.fullname
# To take hidden files into account, you can pass directly through .net, but the file will lose its archive attribute[System.IO.Compression.ZipFile]::CreateFromDirectory(‘c:\test’,‘c:\test.zip’)Related links
Powershell - Simply send objects to different variables
Powershell - Tip - Simply send objects to different variablesPowershell - Testing network connectivity and port accessibility
Testing network connectivity and port accessibility with PowershellPowershell - Display network connections (equivalent to netstat)
Display network connections (listening ports, active connections...)Powershell - Testing name resolution (equivalent to nslookup)
Powershell commands to test name resolution (equivalent to nslookup)Powershell - View and manage DNS configuration of network interfaces
Powershell commands to display and manage DNS configuration of network interfacesPowershell - Managing IP configuration of network interfaces
Powershell commands to view and modify the IP configuration of network interfaces
Follow me on
Support me
E-shop
Last content
Powershell - Simply send objects to different variables
Portsmouth Vintage Travel poster - hueforge
Andalucia vintage poster - hueforge
Paris Travel poster - hueforge