Skip to content

Instantly share code, notes, and snippets.

@c3c
Created June 26, 2018 11:05
Show Gist options
  • Save c3c/66f9faa2a4b9d2c26658580024447672 to your computer and use it in GitHub Desktop.
Save c3c/66f9faa2a4b9d2c26658580024447672 to your computer and use it in GitHub Desktop.
Invoke-ZipFolder.ps1
# Invoke-ZipFolder from https://github.com/EmpireProject/Empire/blob/master/lib/modules/powershell/management/zipfolder.py
# also works on older PowerShell versions, worrying though that it displays a dialog, see https://github.com/EmpireProject/Empire/issues/135
function Invoke-ZipFolder
{
param([string]$Folder, [string]$ZipFileName)
if (-not (Test-Path $Folder)) {
"Target folder $Folder doesn't exist."
return
}
if (test-path $ZipFileName) {
"Zip file already exists at $ZipFileName"
return
}
$Directory = Get-Item $Folder
Set-Content $ZipFileName ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $ZipFileName).IsReadOnly = $false
$ZipFileName = resolve-path $ZipFileName
$ZipFile = (new-object -com shell.application).NameSpace($ZipFileName)
$ZipFile.CopyHere($Directory.FullName)
"Folder $Folder zipped to $ZipFileName"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment