‘Sup PSHomies
So APP-V has this file, AppxManifest.xml, where the Version,VersionID,PackageID is stored amongst other things. My last interaction with software virtualization was when APP-V still went by the name SoftGrid… Yeah… So I was kinda reluctant, that was until I heard that the APP-V client is all about PowerShell! This pleases me… 😉 I guess that’s why my colleague thought of me in the first place… I do love me some PowerShell… Hehe…
So he explained that the .appv file is just a zip file… Wait what? So I can extract the content just like a zip file? Good to know!!! I remember seeing this tactic once used by Bartek Bielawski in his excel module. It would seem that a .xlsx file is also just a zip file.
I’ve been using PowerShell version 5 for quite some time. There are two cmdlets available for zipping and unzipping respectively,Compress- and Expand-Archive. This will get you all the files. My first attempt was to extract all the files and then select the AppxManifest.xml file, but that seemed like quite a lot of unnecessary work for just one file… Hmmm… Guess it’s .NET then…
Before the archive cmdlets the only way to deal with zip file was with you needed to use .NET to extract files from zip. Just load the assembly
Add-Type -assembly 'system.io.compression.filesystem'
Rule of thumb is to use a cmdlet if available, but in this case I only wanted that one file… I checked if expand supported extract a single file, it doesn’t, so using .NET is justified (for the moment)
My first attempt was to copy the appv file and rename it to zip. But then I would need to clean up files/folders afterwards… Why not just read the file eh? Just one thing, you need a handle on the file you opened in order to dispose of the process later down… The function will extract the AppxManifest file and prepend the appv filename to the AppxManifest.xml file, using underscore as a separator, in the subfolder manifest… Whew! Still follow me?
Ok… enough chit-chat here’s the code…
<# Author: I. Strachan Version: 1.0 Version History: Purpose: Extract The AppxManifest.xml file from the .appv file. Get the Version,PackageID and VersionID from AppxManifest.xml #> function Get-AppxManifest { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [ValidateScript({ Test-Path -Path $_ -PathType Container })] [string]$Source ) begin{ #Load Assembly for Zip Add-Type -assembly 'system.io.compression.filesystem' #get AppV Files from parent Folder $appVFiles = Get-ChildItem -Path $Source -Recurse -Filter ('*.appv') $manifestFolder = "$($PSScriptRoot)\Manifest" if(!(Test-Path -Path $manifestFolder)) { Write-Verbose 'Manifest folder does not exist. Creating folder' New-item -Path $manifestFolder -Type Directory | Out-Null } } process{ #get AppxManifest.xml content $appVFiles | ForEach-Object { $FileName = $_.BaseName $FilePath = $_.FullName #Create handle in orde to dispose File later on $hndZipFile = [System.IO.Compression.ZipFile]::OpenRead($_.FullName) $hndZipFile.Entries | Where-Object { $_.FullName -like 'AppxManifest.xml' } | ForEach-Object { $File = Join-Path $manifestFolder "$($FileName)_$($_.FullName)" [IO.Compression.ZipFileExtensions]::ExtractToFile($_, $File, $true) #Typecast to Get XML [XML]$xml = Get-Content $File [PSCustomObject]@{ Version = $xml.Package.Identity.Version PackageId = $xml.Package.Identity.PackageId VersionId = $xml.Package.Identity.VersionId DisplayName = $xml.Package.Properties.DisplayName AppVPath = $FilePath } } #Close handle on File $hndZipFile.Dispose() } } end{} }
Just point the function to the folder hosting the appv files and you’ll get an overview of the Version,VersionID,PackageID,DisplayName and AppVPath
The fun part for me was using .NET to extract that single file. I forgot that you needed to keep a handle on things yourself when using .NET
Hope it’s worth something to you…
Ttyl,
Urv
Error in the code on line 45 character 47. Probably a copy paste error ("$($FileName)). Trying to get what it should be.
LikeLiked by 1 person
Hi Alex,
I’ve updated the function… WordPress sometimes takes quotes too literal… I need to be careful in which mode I’m editing… Visual always gets it wrong…
Regards,
Irwin
LikeLike