Ich habe eine kleine Funktion zum entpacken einer ZIP Datei unter PowerShell <=4 benötigt:
function Expand-ZIPFile($file, $destination)
{
$shell = new-object -com shell.application
$zip = $shell.NameSpace(„$file“)
$DestinationExists = Test-Path $destination
If ($DestinationExists -ne $true)
{
$foo = New-Item $destination -type directory
}
$shell = new-object -com shell.application
$zip = $shell.NameSpace(„$file“)
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item)
}
}
Aufruf mit:
Expand-ZIPFile -file c:\foo.zip -destination c:\folder\
Unter PowerShell 5 wurde dazu eine neue Funktion eingebaut:
Expand-Archive c:\foo.zip c:\folder\