Tag Archives: Microsoft App-V

Automating Microsoft App-V Lightweight Streaming Services with Powershell.

App-V Lightweight streaming services (LWS) is awesome. In particular, its a great utility for enterprises who wish to use App-V but don’t need the user management overhead that comes along with the full product.

For example, when using something brilliant like RES Workspace Manager, you can provision App-V applications, manage licensing requirements and restrict access to applications to pretty much any collection you wish. With utilities like this managing your workspaces the App-V database and management servers are just unnecessary add-ons.

With Lightweight streaming services, you get all the benefit of isolation, streaming and version control but without the additional infrastructure and management overhead. Simply host a network based application depot and point the lightweight streaming servers / clients to the share, Done.

But even with all these great benefits, the key difficulty with Lightweight streaming services is pre-caching the applications before a user needs them and keeping the application content up to date as new updates are added.

Having scripted mechanisms in Batch to perform this function and lost some hair in the process, I’m delighted to say PowerShell handles this job really well. Below find the powershell functions I’ve written to handle the four core tasks and the script I use to tie them all together. I run this script as a startup script after our XenApp servers scheduled restarts, this script will:

  • delete local packages that no longer exist on the content share.
  • Add new packages on the content share.
  • Perform a version check, deleting a local older copy if found.

Note: These scripts assume best practices of the applications being stored in servernamecontentshareappnameapp files.
Add an appv package to the local machine:
Useage:  add-appvpackage -path “servercontentshare” -packagename “packagename”

function add-appvpackage{
       if (test-path $path$packagename$packagename`_manifest.xml){
            pushd $path
            start-process -wait sftmime.exe -argumentlist "add package:$packagename /manifest .$packagename$packagename`_manifest.xml /global"
            start-process -wait sftmime.exe  -argumentlist "load package:$packagename"
          }#end path if
       write-warning "problem with path $path$packagename$packagename`_manifest.xml"}
}#end function

Remove an appv package to the local machine:
Useage: remove-appvpackage -packagename “packagename”

function remove-appvpackage{
    start-process -wait sftmime.exe -argumentlist "delete package:$packagename /global"

Retrieve a list of appv packages on the local machine:
Useage: get-appvlocalpackages

function get-appvlocalPackages{
    $localpackageswmi = get-wmiobject -class Package -namespace rootmicrosoftappvirtclient
    foreach ($package in $localpackageswmi) {
        $packagedetails = New-Object PSObject -Property @{
            }#end object
    }#end for
    return $packages
}#end function

Retrieve a list of appv packages on the content share:
Useage: get-appvremotepackages

function get-appvremotepackages{

    foreach ($package in get-childitem $remotedir){
        [xml]$manifest = get-content $remotedir$package${package}_manifest.xml
        $packagedetails = New-Object PSObject -Property @{
        }#end object
    }#end for
    Return $packages
}#End Function

Gluing it all together into a maintenance script:

#getting package arrays
$locallist=get-appvlocalpackages | sort name
$remotelist=get-appvremotepackages | sort name

#sort the differences to highlight deletes first.
foreach ($difference in COMPARE-OBJECT -referenceobject $locallist -differenceobject $remotelist -property name,version | sort sideindicator){
    if ($difference.sideindicator -eq "<="){
        if ($difference.name -ne $null){
            write-host "removing $($difference.name)"
            remove-appvpackage -packagename $difference.name}
    }#end if
    Else {
        if ($difference.name -ne $null){
            "adding $($difference.name)"
             add-appvpackage -path $remotedir -packagename $difference.name}   
        }#end else
}#end for

To grab a copy of the whole script, follow the jump below:

Continue reading

Quickly delete and re-stream an App-V application with Powershell

I get this problem quite a bit in our environment so threw together a quick Powershell script.

A tech will add revision after revision to an App-V package in the development lifecycle, but when it goes live to production the revisions are so far apart the application rarely works using the cached version even after an sfttray /loadall.

Here’s a quick Powershell script to cleanly remove and read an application:

The usage is below:

update-appvpackage -path "servercontentshare" -package "packagename"

This script assumes you use the best practices on your content share. .e.g. contentshareappnameappname_manifest.xml. If you don’t use this practice, this script wont work for you.

function update-appvpackage{

    if (test-path $path$packagename){
            pushd $path
            write-host "deleting $packagename"
            start-process -wait sftmime.exe -argumentlist "delete package:$packagename /global"
            write-host "Re-Adding $packagename"
            start-process -wait sftmime.exe -argumentlist "add package:$packagename /manifest .$packagename$packagename`_manifest.xml /global"
            write-host "Loading $packagename"
            start-process -wait sftmime.exe -argumentlist "load package:$packagename"
          }#end path if
     Else {
        write-warning "package directory / path not found"}
}#end function

App-V Launcher, an application to quickly troubleshoot in the App-V bubble.

Note: This post has been updated to include an executable for AppV 5 along with the source code if you wish to see how to interact with powershell from .Net.

So here’s your scenario, you’re knee deep in an App-V roll out and a user reports a bizarre issue with a virtual application. You need to get into the bubble to have a look around and the process normally goes something like this:

  • “what’s that command again?”
  • open up a browse and search for it… oh yes, its “sfttray.exe /exe cmd.exe ” and the application name at the end…
  • what’s the application name? oh yes, its a combination of the original application name and the particular version number… “theres no way I can remember that!”
  • launch the sftcmc.msc, and try to find the correct application out of a potentially very long list.
  • copy the name into the command line and pray you don’t close that cmd window soon.

This process always slows me down, so I wrote the following little program to get over this issue, enter App-V Launcher:

This application enumerates cached Microsoft App-V applications and presents you with a list to choose from. Once you select the application you want to work with, you can simply type the executable you need to use inside of the bubble and you can troubleshoot to your hearts content.

Below you’ll find the pre req’s, supported platforms and download. I’ve also included the source code should you need to tweak it to suit your implementation.

I have tested this on:

  • Windows server 2008 r2 with App-V 4.6 sp1
  • Windows server 2003 r2 (x86) with App-V 4.5


  • Microsoft .Net framework 3.5 (.Net 4.0 for appv 5 launcher)

Updated for App-V 5:

I’ve updated the package for app-v 5, cleaner UI and now relies on the powershell commands.


Removing the “Revert to clean state” warning on a Microsoft App-V 4.6 sequencer.

Before I start, I should point out I dont recommend you do this. This is just a how to, if you are like me and ended up with a wrongfully dirty sequencer due to user error (not mine, eherm!) and no snapshot available this may save you some hassle.

When sequencing an application on a “dirty” sequencer, you will receive the following warning as part of the preparation of the client for the sequencing job:

“Package previously created or updated on this computer.” with a resolution of “Revent to clean state.”

If you really want to clear this warning, and are confident your sequencer is in fact clean do the following:

  • open regedit
  • browse to “HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftSoftGrid4.5Sequencer”
  • (“HKEY_LOCAL_MACHINESOFTWAREMicrosoftSoftGrid4.5Sequencer” on an x86 machine)
  • delete the Readybit Dword:

Now just click refresh and its as if you never made a mistake in the first place… (it wasnt me, honest).