Kirx' Blog - kirxblog.wordpress.com

Bulk-update App-V Packages with a new Sequencer | January 26, 2012


Do you want to update all your old SoftGrid / App-V Packages to the newest Sequencer / Client version? Do you need to create Publishing MSIs for a bunch of packages because in the past you didn’t need them but want to use them now? Here is a simple Powershell Script that converts all existing packages within a folder structure recursively.

Recently I was pinged by mail buy a guy who asked me if it is possible to create the “Publishing MSI” for a bunch of App-V Packages. In the past, that organization only used the App-V Management Server, so their Packagaing Guideline did not include the creation of that MSI. About at the same time I realized that I have “a million” of old SoftGrid and App-V Packages that still would do their job, but their inner structure is quite old so the App-V Client would apply some “conversion magic” whenever certain functions of those packages would be executed. Some packages had that “old” Publishing MSI that was not compatible with newer Client versions. And of course non of my packages was compressed before.

So, the guy asked me: “Yeah, you told me that it can be done in Powershell using the Command Line Sequencer… but how?”

Hm, I am not really what you would call a Powershell Expert. This is why I asked my colleague Matthias to “help” me with the App-V Analyzer tool before. But with that sample and some internet search I actually created my first “real” PoSH scripty and here we go:

When you upgrade your App-V Client to a somewhat newer version (like from 4.2 to 4.5 / 4.6 / 4.6 SP1), Microsoft recommends to open and save all packages with the new Sequencer. MS says, that by resaving the packages their “inner structure” gets converted to the new version, resulting in an increased stability and performance. When “legacy” packages are executed on newer clients, some “tweaks” might be applied to let the old packages behave like new ones.

Feature

  • Convert all packages under a folder (subfolders are parsed recursively) to the actual Seqeuncer’s version. Network Shares work as well
  • Create an Publishing MSI for every package
  • Compress every package
  • Keep FB1/FB2 separation

Script

 

##########################################################
##
##    Resave App-V Packages
##
##    2012-26-01 Falko Gräfe
##

##########################################################
## Purpose: Open all App-V Packages of a certain folder recursively and Save them right away
## Create MSI and Compress automatically
## Not implemented: Error Handling and Reporting
## Adjust $StartFolder !!
cls
$StartFolder = 'C:\Data Folders\Packages'
$sprjFileName = ''
# Get all folder names (except for "... ICONS" folders) into one list
# Because we want to process the .sprj AND want to "clean" the old sft(s), just getting the .SPRJs is not enough
$AppVPackagesFolders1 =  Get-Childitem $StartFolder -Recurse | Where {($_.psIsContainer -AND ! ($_.name -match "Icons") )}
#Process each folder
FOREACH ($AppVPackagesFolder in $AppVPackagesFolders1){   # parse each list item
    # Now get the "full name" of the current folder. If the folder doesn't contain an sprj, there is no App-V packagee in there so wie skip it
    $CurrentFolderContent = Get-Childitem $AppVPackagesFolder.FullName | Where {($_.name -match ".sprj")}    
    # Console output
    "Processing "+$AppVPackagesFolder.FullName
    If ($CurrentFolderContent -ne $null){
        # get the SPRJ File Name
        $sprjFileName = Get-Childitem $CurrentFolderContent.FullName | where {$_.name -match ".sprj"}
        # get the "old" SFT File Names (for later deletion)
        $sftFiles = Get-Childitem $AppVPackagesFolder.FullName | where {$_.name -match ".sft"}             
        # specify the Sequencer location
        [string]$ExeFile = '"'+$env:ProgramFiles+"\Microsoft Application Virtualization Sequencer\sftsequencer.exe"+'"'  
        # Compose the command line
        [string]$CmdlineArgument = ' /open:"'+$sprjFileName.FullName+'" /MSI /COMPRESS'
        # Launch the Sequencer, pass the .sprj file name
        Start-Process $ExeFile $CmdlineArgument -wait 
        # Delete every old SFT file in the current folder
        FOREACH ($sftFile in $sftFiles){                       
            remove-item $sftFile.FullName  
        }  #FOREACH 
    }  #IF 
    ELSE{
       # Console output
        "          ... previous folder did not contain any Package files (but may contain folders)"
    }
}   
"Finished"

Preparation and Execution

Before using it, check and adjust the PoSH script. You may save it as “Resave_App-V_Packages.ps1” if you want to use it regulary.

Required adjustments

The value fo $StartFolder. This is the main folder were all your packages are located.

The value for $ExeFile: This is the location of SFTSEQUENCER.EXE. In my example, it’s the default location on a 32bit machine.

The value for $CmdlineArgument: currently includes MSI creation and compression. If you don’t want to have that, delete /MSI and/or /COMPRESS

Execution

Impotant: Do not run against your “original” App-V Content folder. The Sequencer will override each input package!

Make a Backup Copy before!

The Script needs elevated admin permissions to execute (because the Sequencer requires that) and the user needs write access to the Content-Copy folder.

I’m using the Powershell ISE (launched as Administrator) on the Sequencer machin, but you also could use a little CMD to launch it:

set Ps1Path= C:\Data Folders
powershell set-executionpolicy unrestricted
powershell "& '%PS1Path%\Resave_App-V_Packages.ps1'"

Here, you’d have to adjust the path to the Powershell script that you might have saved.

Remember to run the CMD with “run as adminisstrator”.

Limitations

This release has not been tested thoroughly. You use it at your own risk!

There is absolutely no error handling in it. If anything goes wrong, it may delete all “old” SFT files without creating new ones. The Sequencer may crash.

To check for issues, use the Sequencer’s error log (sft-seq-log.txt in the Sequencer’s Program / Logs folder).

It’s my first PoSH script. Remember that. I know it’s not that smart at all (no GUI, no Command Line parameters…, no PoSH specific extra tweaks) Just Quick and Dirty.

Advertisements

5 Comments »

  1. […] Kirx Blog […]

    Pingback by - Cliff Davies — January 26, 2012 @ 17:51

  2. Awesome, this is just what I was looking for, thank you.

    Comment by John — May 8, 2012 @ 16:08

  3. Hi
    Tried running your script but i get the following error

    Remove-Item : Cannot bind argument to parameter ‘Path’ because it is null.
    At C:\ps\Resave_App-V_Packages.ps1:38 char:24
    + remove-item <<<< $sftFile.FullName
    + CategoryInfo : InvalidData: (:) [Remove-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RemoveItemC
    ommand

    Comment by chas — January 16, 2013 @ 00:15

    • Hi,

      the error message indicates that there isn’t an old SFT file. I added this clean-up because the Sequencer creates a new (_2, _3, …) sft file, so you’d get orphaned old Versions of it.
      As a check you could simply add a ‘#’ before that remove-item line, this disables it.

      Comment by kirxblog — January 16, 2013 @ 09:20

      • Thanks That works.
        Great Script by the way.

        Comment by Chas — January 30, 2013 @ 17:22


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: