Forum Discussion
CS_HelpDesk
2 years agoGoTo Contributor
Compress a file or folder to a ZIP archive.
---
$source = $null
$destination = $null
$includeRootFolder = $false
$overwrite = $false
$parent = Split-Path $destination
If (-Not (Test-Path -Path $parent -PathType Container))
{
New-Item -Path $parent -ItemType Container
}
$isFile = Test-Path -Path $source -PathType Leaf
if (-Not $includeRootFolder -and -Not $isFile)
{
$source = Join-Path $source "*"
}
Compress-Archive -Path $source -DestinationPath $destination -Force:$overwrite