Jaa


App-V 5.0 Client PowerShell Deep Dive

written by - Robert Doverspike, Software Development Engineer

PowerShell allows system admins to perform a vast array of tasks, all while leveraging the support of .NET’s extensive libraries. Microsoft Application Virtualization has added PowerShell cmdlet support to its 5.0 release, giving system administrators a powerful tool for interfacing with the App-V 5.0 client. This article will cover a variety of common tasks to get you started on managing the App-V 5.0 client through PowerShell, and cover the basics of mixing different cmdlets together for more advanced scenarios.

· Managing Packages

· Managing Connection Groups

· Managing Publishing Servers

· Advanced Scripting

· Getting Help 

 

Setup

To get started with Poweshell cmdlets, open an elevated (running as Administrator) PowerShell window on your App-V 5.0 client machine and type the following command to load the App-V 5.0 client module cmdlets.

 Import-Module AppvClient

If App-V is installed on the machine, but PowerShell cannot resolve AppvClient, try typing Import-Module "C:\Program Files\Microsoft Application Virtualization\Client\AppvClient\AppvClient.psd1" instead. The path can vary based on installation configuration.

 

App-V Client Nouns

Since the format of a PowerShell cmdlet takes the form of Verb-Noun, it is useful to see all the available nouns to understand the capabilities offered by the cmdlets.

Below is a listing of available nouns:

AppvClientApplication – An individual application that exists in an App-V package.

AppvClientConnectionGroup – A connection group used to allow multiple packages to interact with one another in the same virtual environment, while remaining isolated from the host operating system. See Deploying Connection Groups in Microsoft App-V v5 or Connection Groups Internals (App-V 5.0) for more information on connection groups.

AppvClientConfiguration – A configuration value for a setting of the App-V Client (E.g. EnablePackageScripts, AllowHighCostLaunch, PackageInstallationRoot)

AppvClientMode – The current mode (normal or uninstall) of the client.

AppvClientPackage – An App-V package that is available for use on the App-V Client.

AppvClientReport – An XML formatted report to be sent to an App-V Reporting Server that aggregates usage data from App-V Clients.

AppvPublishingServer – An App-V server that hosts metadata about the packages available to the client over the network.

AppvVirtualProcess – An App-V virtual process running a virtual app on the App-V client.

All cmdlets associated with a given noun can be viewed by typing Get-Help, for example

 Get-Help AppvClientPackage

Get-Help also accepts wildcards in the name parameter. Add the –Full parameter to see the full documentation.

 

Managing packages

Add and publish a package

The most basic operations needed to begin using virtual applications are to first add an App-V 5.0 package to the client on your machine, then publish the package so the current user can see it.

 # Add the package at the specified location            
$Contoso = Add-AppvClientPackage \\appvpackages\Contoso\ContosoApp.appv            
# Publish the added package to the current user            
Publish-AppvClientPackage $Contoso

Packages can be published globally to all users of a machine or to the current user. See Get-Help Publish-AppvClientPackage for details.

Querying packages

As its name implies, Get-AppvClientPackage returns a list of all the App-V packages currently on the system. By combining different parameter sets such as -Name and -Version, -PackageId and -VersionId, you can query the packages on the system based on their attributes.

By specifying the -All switch parameter, this cmdlet will return the union of all packages on the system, either added or published. In the absence of the -All switch parameter, Get-AppvClientPackage by default will return only the currently published packages.

 # Explicitly look up package by package GUID and version GUID
Get-AppvClientPackage -PackageId 43703c67-dbdc-4da5-beb4-4f84cc028c02 
-VersionId 614c9aa3-8964-468d-a8b2-8c65215910d9 -All

Note that Get-AppvClientPackage returns nothing if no packages are found.

You may also look up packages using a second parameter set, which is by Name and Version.

 # Look up package with the Name parameter set using * as a wildcard
Get-AppvClientPackage -Name Contoso* -Version 2*

Be aware of types! Remain aware of the object types that each cmdlet parameter set expects using Get-Help. Note that in the below example the first block will not work as one would initially expect, because PowerShell will automatically convert what looks like a GUID into a String for the Name parameter set.

 # Will not work because the GUID is treated as a String for the -Name parameter
Get-AppvClientPackage 43703c67-dbdc-4da5-beb4-4f84cc028c02


# Works because $GUID is a GUID type, which matches the –PackageId parameter
$GUID = [GUID]"43703c67-dbdc-4da5-beb4-4f84cc028c02"
Get-AppvClientPackage $GUID
Remove an existing package

We have already shown how to add and publish an App-V 5.0 package, and now we’ll show the converse operations – unpublish and remove.

 # Search for existing package by name
$Contoso = Get-AppvClientPackage -Name Contoso*
# Unpublish the package
Unpublish-AppvClientPackage $Contoso
# Remove the package
Remove-AppvClientPackage $Contoso

 

Managing connection groups

Combining packages into a connection group

Packages can be combined in App-V 5.0 into an entity called a connection group. A connection group allows you to run all of the virtual applications as a defined set of App-V 5.0 packages in a single virtual environment. Refer to the links earlier in this blog post for more information on maintaining and creating connection groups. Here we’ll show how to enable a connection group with two packages.

 # Add and publish a package
$Contoso = Add-AppvClientPackage \\appvpackages\Contoso\ContosoApp.appv
Publish-AppvClientPackage $Contoso

# Add and publish another package
$ContosoUI = Add-AppvClientPackage \\appvpackages\Contoso\ContosoUI.appv | Publish-AppvClientPackage

As shown above, the output of one cmdlet may often be piped as the input to another cmdlet (if the first cmdlet returns a valid parameter for the second cmdlet).

 # Add the connection group, providing the path to its xml descriptor file
$ContosoFull = Add-AppvClientConnectionGroup \\appvpackages\Contoso\ContosoAppWithUI.xml
# Enable the connection group
Enable-AppvClientConnectionGroup $ContosoFull

Similar to packages, connection groups can be enabled globally to all users of a machine or to the current user. See Get-Help Enable-AppvClientConnectionGroup for details.

 

Managing publishing servers

Add and sync to a publishing server

Publishing servers host package metadata that can be synchronized with a client. The most fundamental operation involves adding an existing publishing server and synchronizing its metadata with your local client.

 # Add a publishing server
$pubServer = Add-AppvPublishingServer -URL https://appvpublishing.contoso.com 
-Name Alpha
# Sync the local client with the added publishing server
Sync-AppvPublishingServer $pubServer
Conditional backup publishing server

This is an example script which adds a backup publishing server conditional on the name of the main publishing server.

 $mainPub = Get-AppvPublishingServer 1
if ($mainPub.Name -eq "Alpha") {
 $backupUrl = "https://alpha.backup.contoso.com"
}
elseif ($mainPub.Name -eq "Bravo") {
 $backupUrl = "https://bravo.backup.contoso.com"
}
$backupPub = Add-AppvPublishingServer -URL $backupUrl -Name Backup

 

Advanced Scripting

To illustrate the value of using PowerShell to expose and interact with App-V Client dynamically, here is an example of App-V Client cmdlets being used in an advanced scripting scenario. This script roughly counts the number of seconds taken for the package to be fully downloaded from the network.

 # Add and publish the package 
$package = Add-AppvClientPackage "\\appvpackages\package.appv" 
| Publish-AppvClientPackage

# Start the mount operation in the background, passing in the package Name as an argument
Start-Job {Get-AppvClientPackage $args[0] | Mount-AppvClientPackage } 
-ArgumentList @($($package.Name))

# Count the seconds until the package is fully loaded
$i = 0;
while (($percentLoaded = $package.PercentLoaded) -lt 100) {
    Write-Output "PercentLoaded for $($package.Name) is $percentLoaded";
    $i++;
    sleep(1);
};
Write-Output "$($package.Name) loaded in $i seconds.";

 

Getting Help

These examples should be enough to get you started, and to convince you that performing complex automated App-V tasks can be executed trivially using PowerShell. You can find more information on the cmdlets mentioned here, as well as others, in the official documentation for all App-V Client cmdlets, available through the built in PowerShell help infrastructure. There are just a few PowerShell cmdlets you’ll need to know to access the documentation.

To get a list of all of the AppvClient commands use Get-Command.

 Get-Command -Module AppVClient

Again, for help on a specific cmdlet or all cmdlets with a given phrase use Get-Help <phrase>, and you can add the -Full switch parameterfor additional details.

Comments

  • Anonymous
    January 01, 2003
    PowerShell rocks! - Everywhere!

  • Anonymous
    January 01, 2003
    Great Info . I Try a lot to import " Import-Module AppvClient" But it doesn't work and after a lot of searching find your great blog .

  • Anonymous
    March 15, 2013
    Very nice Anurag and thanks for the great info!  Can you please point me to where I can find instructions for hiding and disabling  the appv icon in systray?  In 4.6, one could get to the appv client via mmc, choose "interface" and select "Do not show appv client."  How would do that via powershell?  Thanks in advance!

  • Anonymous
    February 16, 2014
    Yes, there is a learning curve with the new release of App-V. This is why it is extremely important that

  • Anonymous
    February 04, 2015
    After App-V 5 SP2+ there is actually no command center shown n the task bar. Even if you do install the GUI client. Another note is that the default client is power Shell only and if you need to use the GUI. You have to install that on top of the default client or vice versa.

  • Anonymous
    February 11, 2015
    @yahya before import-module appvclient try this: powershell.exe -executionpolicy bypass

  • Anonymous
    June 30, 2015
    ~ John Behneman | Senior Support Escalation Engineer Hello everyone, John Behneman here again. I’d like

  • Anonymous
    November 12, 2015
    Great post from your hands again. I loved the complete article.
    By the way nice writing style you have. I never felt like boring while reading this article.
    I will come back & read all your posts soon. Regards, Lucy.

  • Anonymous
    February 04, 2016
    Note: At least when AppV is integrated with SCCM the Get-AppVPackage MUSt have the -all parameter specified or it does not return anything e.g.
    Get-AppvClientPackage -Name Contoso* -all