Skip to content

Instantly share code, notes, and snippets.

@mattleibow
Created February 12, 2021 01:53
Show Gist options
  • Save mattleibow/eaa55a9088bb52d4d795e14754d78707 to your computer and use it in GitHub Desktop.
Save mattleibow/eaa55a9088bb52d4d795e14754d78707 to your computer and use it in GitHub Desktop.
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[String] $SourceDir,
[Parameter(Mandatory=$true)]
[String] $DestinationDir
)
$ErrorActionPreference = "Stop"
New-Item -Type Directory $DestinationDir -Force | Out-Null
Write-Host "Compressing all the directories(s) in '$SourceDir'..."
$folders = Get-ChildItem $SourceDir -Directory
foreach ($dir in $folders) {
$name = $dir.Name
$dest = "$DestinationDir/$name.zip"
Compress-Archive -Path "$dir/*" -DestinationPath $dest -Force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment