Skip to main content

How to read the manifest of an appx package file

Reading the manifest of an installed appx package is easy, however today a colleague of mine was working on a custom install script for appx packages and quickly found out that Microsofts Get-AppxPackageManifest can’t be used on an actual appx file.

Some quick testing later and we now have an extended version of the function that handles already installed packages as well as appx package files.

function Get-POPSAppxPackageManifestExtended{
    
    param($Package, $User)

    if(Test-Path $Package){
        Add-Type -Assembly "System.IO.Compression.FileSystem"
        $zip = [IO.Compression.ZipFile]::OpenRead($Package)
        $file = $zip.Entries | Where-Object { $_.Name -eq "AppxManifest.xml"}
        $stream = $file.Open()

        $reader = New-Object IO.StreamReader($stream)
        $xml = [XML]$reader.ReadToEnd()

        $reader.Close()
        $stream.Close()
        $zip.Dispose()

        $xml

    }else{
        if($User){
            Get-AppxPackageManifest -Package $Package -user $User
        }else{
            Get-AppxPackageManifest -Package $Package
        }
    }

}
Share

Leave a Reply

Your email address will not be published. Required fields are marked *