Select Page

When I’m building an APPV application, as best practice, I do so in VMs, right… and I need to quickly test it in the VMs to make sure the app functionality is all there… so my config is this… take the script below, copy it to your client VM you use for testing into the folder C:\Users\Public\Downloads. Make a shortcut on your desktop of your VM to the Public\Downloads folder so you can quickly drag and drop from your desktop into the VM… then make a shortcut on your desktop below your shortcut to your folder and use the command for the shortcut:

C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe -file “C:\Users\Public\Downloads\Publish-apps.ps1”

To test an app in your vm, copy the folder from your desktop or whatever location you’ve saved your app outside your sequencing VM. Right-click and copy the folder to the shortcut on your desktop for the \Public\Downloads folder… then right-click and RunAs Administrator the shortcut to publish the virtual app… it’ll iterate through the Public\Downloads folder for any appv applications and, one by one, publish them globally (we actually don’t publish globally in production but this is valid for testing application functionality).

Here’s the script for publishing the app (in my example above, it’s named Publish-apps.ps1):

# Automated script for publishing APPV5 applications for testing on client

# Show an Open Folder Dialog and return the directory selected by the user.
function Read-FolderBrowserDialog([string]$Message, [string]$InitialDirectory, [switch]$NoNewFolderButton)
{
    $browseForFolderOptions = 0
    if ($NoNewFolderButton) { $browseForFolderOptions += 512 }

    $app = New-Object -ComObject Shell.Application
    $folder = $app.BrowseForFolder(0, $Message, $browseForFolderOptions, $InitialDirectory)
    if ($folder) { $selectedDirectory = $folder.Self.Path } else { $selectedDirectory = '' }
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($app) > $null
    return $selectedDirectory
}

$Published = 0
$SourceFolder = "C:\Users\Public\Downloads"
$PkgArray = Get-ChildItem $SourceFolder -Recurse | ?{ $_.PSIsContainer }

ForEach($Pkg in $PkgArray) {

    $APPVFiles = get-ChildItem $SourceFolder\$Pkg\*.appv


    ForEach($File in $APPVFiles) {

        write-host "Add-APPVClientPackage -Path $SourceFolder\$Pkg\$File | Publish-AppvClientPackage -Global -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null"
        Add-AppvClientPackage -Path $File | Publish-AppvClientPackage -Global -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null
        If ($Error) {
                            
            $Skipped++
            write-host "Skipping appv file: $File" -foregroundcolor red
            $Error.Clear()
        }
        Else {
        
            $published++
            write-host "Successfully published file: $File" -ForegroundColor Green

        }
                                                                                                                    
    }  

}

If ($published -eq 0) {

    Write-host "No apps found to publish..."
    Write-host "`n"
}

Else {

    Write-host "Published $published apps."
    Write-host "`n"

}


write-host "Press any key to continue..."
[void][System.Console]::ReadKey($true)

NOTE: If you’d like to allow the user to choose the folder where the APPV applications reside, feel free to use the function to select the folder… obviously, above, I’ve chosen to always use the same folder and, as a result, it takes fewer clicks to get the job done.