How to extract a specific folder from a zip file

Hi,

I have a zip file contains folders, sub folders and files.

I want to extract a specific sub folder along with files and folders in it.

Can anyone suggest a way to accomplish this. I tried the below code but no luck.

$xtrctfolder = "Valueadd\Data\Current\admin\production\"
$destination = "D:\Dinesh\Final_xtract"

Add-Type -Assembly System.IO.Compression.FileSystem
$zip = [IO.Compression.ZipFile]::OpenRead($sourcePath)
$zip.Entries | where {$_.Name -eq $xtrctfolder} | foreach {
	
	$target_path 	= [System.IO.Path]::Combine($destination, $_.Name)
    $target_folder 	= [System.IO.Path]::GetDirectoryName($target_path)
	
	if(!(Test-Path $target_folder ))
	{
        New-Item -ItemType Directory -Path $target_folder | Out-Null 
    }
	
	if(!$target_path.EndsWith("\"))
	{
                [System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, $target_path, $true);
    }
}

Thanks
Dinesh

I would use 7zip. You just need 7z.exe and 7z.dll for the command line version.

7z e archive.zip folder -odest

Hi Dinesh,

Try using this function:

https://gist.github.com/pwshliquori/c244704a321bab7e0196a3a5d5aa0b21

pwshliquori