logo
parallax-small

PowerShell Extract Item from ZIP (Appv)

More
5 years 4 months ago - 5 years 4 months ago #277 by Ordale
Ordale created the topic: PowerShell Extract Item from ZIP (Appv)
Greetings,

I need to lookup a verionid of the new AppV format with PowerShell. Inside the AppV package format a XML is located with this information.

With PowerShell i need to extract information from a xml file inside the AppV Package. I have tried several possibilities. I haven't got it working for just one file.

This is my script at the moment:

[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )
$a = [System.IO.Compression.ZipFile]::OpenRead("C:\TEMP\TestAppV5\7ZIP_7ZIP_9_2\7ZIP_7ZIP_9_2.appv")

#$c = [System.IO.Compression.ZipFile]::ExtractToDirectory("C:\TEMP\TestAppV5\7ZIP_7ZIP_9_2\7ZIP_7ZIP_9_2.appv","c:\Temp")

$a.Entries.
#$a.Entries
#$b = $a.GetEntry("AppxManifest.xml")


Can someone help met with extracting information from the appxmanifest.xml, which is located in a "zip" file AppV with minimal efforts (not extracting the whole zip, but part of it)? I am able to use PowerShell 3.

Greetings,
Roel Beijnes
Last Edit: 5 years 4 months ago by Ordale.

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago - 5 years 4 months ago #278 by Dennis Geerlings
Dennis Geerlings replied the topic: Re: PowerShell Extract Item from ZIP (Appv)
Have a look at the documentation for OpenRead. It shows the specific example you are looking for.
string zipPath = @"c:\example\start.zip";
            string extractPath = @"c:\example\extract";

            using (ZipArchive archive = ZipFile.OpenRead(zipPath))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.Name == "appxmanifest.xml")
                    {
                        entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
                    }
                }
            }


Sure it's not PowerShell but C# looks enough like PowerShell that it should be easy to translate. You will probably have a bit more text to define the different types
Last Edit: 5 years 4 months ago by Dennis Geerlings.

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago #279 by marleenoh
marleenoh replied the topic: Re: PowerShell Extract Item from ZIP (Appv)
Hi Roel,

I extract the xml file to a temorary location, than I use following method to read information out of the AppxManifest.xml file
[xml]$AppxManifest = Get-Content C:\Temp\AppxManifest.xml

you can browse the namespace for any value like
$AppExeFile = $AppxManifest.Package.Applications.Application.Target

to get the name of a package:
$PackageName = $AppxManifest.Package.Properties.DisplayName

/vkleinerde

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago #286 by Ordale
Ordale replied the topic: Re: PowerShell Extract Item from ZIP (Appv)
EUREKA! I have found a way to extract just "one" file from the ZIP

This is the script in a primal form...

[STRING]$Zipfile = "C:\TEMP\7ZIP_7ZIP_9_2\7ZIP_7ZIP_9_2.appv"
[STRING]$Filename = "AppxManifest.xml"
[STRING]$Destination = $env:TEMP
[STRING]$FILELOCATION = "$Destination\$Filename"

[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" ) > Out-Null
$ZIPSTREAM = [System.IO.Compression.ZipFile]::OpenRead($Zipfile)
$FILESTREAM = New-Object IO.FileStream ($FILELOCATION) ,'Append','Write','Read'

foreach ($ZIPPEDFILE in $ZIPSTREAM.Entries)
{
if ($ZIPPEDFILE.Name -eq $Filename)
{
$FILE = $ZIPPEDFILE.Open()
$FILE.CopyTo($FILESTREAM)
$FILE.Close()
}
}
$FILE.Close()
$FILESTREAM.close()

Thanks for the help in creating this script

Please Log in or Create an account to join the conversation.