App-V 5.0 standalone – Add Packages and Connection Groups from file share

If you are running App-V without the complete infrastructure or SCCM you normally store all your packages on a file share.
Attached you find a small script that connects to a given file share, searches for all .appv files in it and loads all the found packages on the target system. If you have connection groups this script also loads these afterwards.
The script was built to load the packages to PVS hosts at startup via scheduled task. Therefore it is possible to specify the file server name as parameter.

The file structure on the file server looks like this (you can change it to whatever you like):

App-V Packages reside here: \\FILESERVER\Appv
Connection Groups reside here: \\FILESERVER\Appv\AppV_Connection_Groups

You should take care that all of the packages in an Connection Group are available and loaded before loading the respective Connection Groups.

Here is the script. Be sure to save the script and declare the file server name as parameter when starting the script (e.g. load_appv.ps1 FILESERVERNAME):

param($fileserver="fileserver")
$Apphub='\\' + $fileserver + '\Appv'

# Import necessary Module vor App-V
Import-Module AppvClient

# Get loaded Connection Groups and remove them first
Get-AppvClientConnectionGroup | Stop-AppvClientConnectionGroup | Remove-AppvClientConnectionGroup

# Get loaded packages and remove them
Get-AppvClientPackage | Stop-AppvClientPackage | Remove-AppvClientPackage

# List all files with the suffix .appv
Get-ChildItem $apphub\*_appv -recurse -Force | Where-Object { $_.Extension -match ”.appv” }

# Add, mount and publish these App-V applications
ForEach-Object {
Add-AppvClientPackage -Path $_.FullName | Mount-AppvClientPackage | Publish-AppvClientPackage -Global
}

# Add Connection Groups
# List all files with the suffix .xml and store them in array $CG
$CG =Get-ChildItem $Apphub\AppV_Connection_Groups -recurse -Force | Where-Object { $_.Extension -match ”.xml” }

# Add, mount and publish these App-V Connection Groups
$CG | ForEach-Object {
Add-AppvClientConnectionGroup -Path $_.FullName | Mount-AppvClientConnectionGroup | Enable-AppvClientConnectionGroup -Global
}

 
Further information can be found here:
http://www.virtualvibes.co.uk/app-v-5-0-standalone-mode-adding-and-publishing-a-package/
http://technet.microsoft.com/en-us/library/jj713474.aspx
http://stealthpuppy.com/creating-app-v-5-0-connection-groups-with-powershell/

By:

Posted in: