PoshCode Logo PowerShell Code Repository

App-V publish 4 Citrix by thecuriousgeek 13 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/6332"></script>download | new post

Generic script for Citrix PVS and App-V to publish apps without the need for a management and database server for App-V. Generic script doesn’t need to be updated for every change or app so the image wont have to be opened and sealed every time. The published app in the XenApp console passes the necessary information for each new published app, making it easy to add apps on the fly and not have to modify the PVS image. This script should be not necessary if you have XenApp 7.8 or higher.

  1. ###################################################################
  2. ##  Description:  Generic script for publishing and launching App-V
  3. ##  packages in Citrix published app is calls the script and passes
  4. ##  it the name of the package and the name of the EXE to launch.  
  5. ##  App-V packages should be saved in a DFS structure that uses the
  6. ##  name of the app as the folder.
  7. ##
  8. ##  This script is provided as is and may be freely used and
  9. ##  distributed so long as proper credit is maintained.
  10. ##
  11. ##  Written by: thegeek@thecuriousgeek.org
  12. ##  Website:  http://thecuriousgeek.org
  13. ##  Date Modified:  05-01-2016
  14. ###################################################################
  15.  
  16.  
  17. param(
  18.         [string]$appName,
  19.         [string]$exeName
  20. )
  21.  
  22. # Window message to the user so they don't think nothing is happening
  23. Write-Host "`n`n                        Your application is loading..."
  24.  
  25. Import-Module AppvClient
  26. # Try and get package to see if it's loaded
  27. $package = Get-AppVClientPackage -Name $appName
  28.  
  29. # If the package isn't already loaded, load it
  30. If ( !$package ) {
  31.         Try {
  32.                 # Add and publish package.  Make sure to update with your own path
  33.                 $package = Add-AppVClientPackage \\PathToApp-VPackageStorage\$appName\$appName.appv
  34.                 Publish-AppVClientPackage $appName -Global | Out-Null
  35.                 $didComplete = $true
  36.         } Catch {
  37.                 # If it didn't complete, popup an error message to the user with details
  38.                 $errorMessage = "Error Item: $_.Exception.ItemName `n`nError Message: $_.Exception.Message"
  39.                 $didComplete = $false
  40.                 $wshell = New-Object -ComObject Wscript.Shell
  41.                 $wshell.Popup($errorMessage,0,"Error loading application",0x0)
  42.         }
  43. } else {
  44.         # Package is already loaded
  45.         $didComplete = $true
  46. }
  47.  
  48. # In order to know when the app has launched, we'll check the number of window titles
  49. # This is the count before we try to start the app
  50. $windowTitleCount = (get-process | where {$_.MainWindowTitle}).Count
  51.  
  52. If ($didComplete) {
  53.         # Get the local package directory as set in App-V Config, used for building path to EXE
  54.         # Powershell can't expand regular environment variables so have to use CMD to echo it back
  55.         $cmdExpand = "cmd /c echo $( (Get-AppVClientConfiguration | where {$_.Name -eq 'PackageInstallationRoot'}).Value )"
  56.         $packageRoot = Invoke-Expression $cmdExpand
  57.         $packagePath = "$packageRoot\$($package.PackageId)\$($package.VersionId)\Root\VFS"
  58.         # Pull in deployment config because it contains the path to all executables.  Make sure to update with your own path
  59.         [XML]$packageConfig = Get-Content "PathToApp-VPackageStorage\$appName\$($appName)_DeploymentConfig.xml"
  60.         $packageApps = $packageConfig.DeploymentConfiguration.UserConfiguration.Applications.Application.Id
  61.         # Loop through each app/exe listed in the config and find the one that contains the $appExe passed to the script
  62.         ForEach ($app in $packageApps) {
  63.                 If ($app -match $exeName) {
  64.                         $appPath = $app
  65.                         break
  66.                 }
  67.         }
  68.         # Get rid of the special characters App-V uses to reference variables in it's application path so we can create the real path
  69.         $appPath = $appPath -replace "(\[|\{|\}|\])",""  #previous regex  [^0-9a-zA-Z\\\s\.]
  70.         $fullPath = "$packagePath\$appPath"
  71.         Start $fullPath
  72.        
  73.         # Check number of window titles again and keep looping until the count is greater than the starting one we took earlier
  74.         $currentTitleCount = (get-process | where {$_.MainWindowTitle}).Count
  75.         While ($windowTitleCount -ge $currentTitleCount) {
  76.                 $currentTitleCount = (get-process | where {$_.MainWindowTitle}).Count
  77.         }
  78. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me