Sunday, June 20, 2010

Extracting files in PowerShell without third party components

Sometimes it is not acceptable to install or use third party components such as 7-zip or the PowerShell Community Extensions onto machines (particularly because they are not digitally signed). This script will extract files using the shell API:


if(-not (test-path $DestinationFolder))
    md $DestinationFolder | Out-Null

$absoluteSource = resolve-path $SourceFile | select -ExpandProperty path
$absoluteDestination = resolve-path $DestinationFolder | select -ExpandProperty path

$app = new-object -ComObject Shell.Application
$archive = $app.Namespace($absoluteSource).Items()
$dest = $app.Namespace($absoluteDestination)


Post a Comment