Last active
July 27, 2025 15:36
-
-
Save everydayintech/c8145593e906921981e8a21e1457eb3c to your computer and use it in GitHub Desktop.
Sane ZIP functions for your PowerShell profile. Create a ZIP archive of a specified directory in the current location without nesting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function MkZip { | |
| [CmdletBinding()] | |
| param ( | |
| [Parameter( | |
| Mandatory = $true, | |
| ValueFromPipeline = $true | |
| )] | |
| [string]$Directory | |
| ) | |
| [System.IO.DirectoryInfo]$DirectoryInfo = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Directory) | |
| Compress-Archive ` | |
| -Path "$($DirectoryInfo.FullName)*" ` | |
| -DestinationPath (Join-Path (Get-Location) "$($DirectoryInfo.BaseName).zip") ` | |
| -CompressionLevel Optimal | |
| } | |
| function ExpZip { | |
| [CmdletBinding()] | |
| param ( | |
| [Parameter( | |
| Mandatory = $true, | |
| ValueFromPipeline = $true | |
| )] | |
| [string]$File | |
| ) | |
| [System.IO.FileInfo]$FileInfo = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($File) | |
| Expand-Archive -Path $FileInfo.FullName -DestinationPath (Join-Path (Get-Location) $FileInfo.BaseName) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment