mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-08 17:14:28 +01:00
30 lines
786 B
PowerShell
Executable File
30 lines
786 B
PowerShell
Executable File
<#
|
|
.SYNOPSIS
|
|
new-zipfile.ps1 [<directory>]
|
|
.DESCRIPTION
|
|
Creates a new .zip file from a directory
|
|
.EXAMPLE
|
|
PS> ./new-zipfile C:\Windows
|
|
.NOTES
|
|
Author: Markus Fleschutz · License: CC0
|
|
.LINK
|
|
https://github.com/fleschutz/PowerShell
|
|
#>
|
|
|
|
param([string]$directory = "")
|
|
|
|
try {
|
|
if ($directory -eq "" ) { $directory = read-host "Enter the path to the directory to zip" }
|
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
|
|
|
$directory = resolve-path $directory
|
|
compress-archive -path $directory -destinationPath $directory.zip
|
|
|
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
|
"✔️ created zip file $($directory).zip in $Elapsed sec"
|
|
exit 0 # success
|
|
} catch {
|
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
|
exit 1
|
|
}
|