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 or make a donation. 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 - 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 interfacesPowershell - Managing the status and configuration of network interfaces
Powershell commands to view and modify the status and configuration of network interfaces (disable IPv6, enable/disable an interface)
Follow me on
Support me
Last content
Powershell - Testing network connectivity and port accessibility
Powershell - Display network connections (equivalent to netstat)
Powershell - Testing name resolution (equivalent to nslookup)
Powershell - View and manage DNS configuration of network interfaces
Powershell - Managing IP configuration of network interfaces
Powershell - Managing the status and configuration of network interfaces
Powershell and the Left Hand Side
Powershell - Managing disks, partitions and volumes