OpsaC - Operating as PowerShell code
published: December 17, 2014 author: Tinu tags: ZIP categories: PowerShell
function ExtractZipArchive{
<#
.SYNOPSIS
Extract an archive
.DESCRIPTION
Extract an archive from zip file
.PARAMETER Archive
Local path to the archive
.PARAMETER Path
Local path where to extract
.EXAMPLE
ExtractZipArchive -Archive 'U:\tmp\archive.zip' -Path 'U:\tmp\archive'
#>
param(
[Parameter(Mandatory=$true)][String] $Archive,
[Parameter(Mandatory=$true)][String] $Path
)
$ret = $true
$function = $($MyInvocation.MyCommand.Name)
$option = 16 #Click "Yes to All" in any dialog box displayed.
try{
$shell = new-object -com shell.application
if ($psdebug){write-host "$($function) Shell.Application initiated"}
$zip = $shell.NameSpace($Archive)
if ($psdebug){write-host "$($function) Shell.NameSpace initiated"}
foreach($item in $zip.items()){
$shell.Namespace($Path).copyhere($item, $option)
if ($psdebug){write-host "$($function) Extract file"}
}
}
catch [Exception]{
write-host "$($function): Params($($Archive), $($Path)): $($_.Exception.Message)"
$ret = $false
}
return $ret
}