Skip to content

Instantly share code, notes, and snippets.

@everydayintech
Last active July 27, 2025 15:36
Show Gist options
  • Select an option

  • Save everydayintech/c8145593e906921981e8a21e1457eb3c to your computer and use it in GitHub Desktop.

Select an option

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.
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