<< Back to Script Library

APPV5: Unpublish Package (User)

This SBA will unpublish an App-V package for the current user
Version: 2.4.5
Created: 2015-06-19
Modified: 2022-10-12
Creator: Nathan Sperry
Downloads: 99
Tags: $User App-V Unpublish
The Script Copy Script Copied to clipboard
#Requires -Version 3.0

<#
    .SYNOPSIS
    This script will unpublish an App-V application for a user

    .DESCRIPTION
    This script will unpublish an App-V application for a user

    .LINK
    http://virtualengine.co.uk

    NAME: N/A
    AUTHOR: Nathan Sperry, Virtual Engine
    LASTEDIT: 05/06/2015
    VERSI0N : 1.0
    WEBSITE: http://www.virtualengine.co.uk

#>

$ErrorActionPreference = 'Stop'

# Check if App-V client is installed
Function Get-AppVClient{

    <#
    .SYNOPSIS
    This function determines if the App-V client is installed
    .DESCRIPTION
    This function determines if the App-V client is installed
    .EXAMPLE
    Get-AppVClient
    Returns true or false.
    .NOTES
    NAME: Get-AppVClient
    AUTHOR: Nathan Sperry, Virtual Engine
    LASTEDIT: 05/06/2015
    WEBSITE: http://www.virtualengine.co.uk
    KEYWORDS: App-V,App-V ,VirtualEngine,AppV5
    .LINK
    http://virtualengine.co.uk
    #>

    ## TTYE - check if this is the built-in AppV
if ([boolean](Get-Command -Name Get-AppvStatus -ErrorAction SilentlyContinue)) {
    if ((Get-AppvStatus).AppVClientEnabled -eq $true) {
        return $true
    }
}

$Installed = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | where Displayname -match 'Microsoft Application Virtualization' | Select-Object Displayname

if ($Installed -ne $null) {return $true} else {return $false}

}

$appvname = $args[0]

if (Get-AppVClient -eq $true)
{

    # Import App-V PoSH Module to make sure its loaded
    If ( ! (Get-module AppVClient ))
    { 

        # Find Installation Path
        $strAppVClient = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\AppV\Client
        $strInstallPath = $strAppVClient.InstallPath
     Import-Module ($strInstallPath + "AppvClient\AppvClient.psd1")
    }

    try
    {
        
        $allpackages = Get-AppvClientPackage -All
        $packages = $allpackages | where {$_.Name -like $appvname}

        if ($packages.count -ge 1)
        {

                foreach ($package in $packages)
                {
                    If ($package.IsPublishedGlobally -eq $true)
                    {
                         $result = unpublish-AppvClientPackage -Name $package.Name
                         Write-host $package.Name 'has been unpublished for the current user'
                    }
                    else
                    {
                        Write-Output ($package.Name + ' is not currently published to this user')
                    }

                }

        }
        else
        {
            Write-Warning "No App-V packages that match '$appvname' are present on this device"
        }
    }
    catch
    {
     
        $ErrorMessage = $_.Exception.Message
        Write-Output $ErrorMessage

    }
}
Else
{
    Write-Warning 'App-V 5.x client is not installed'
}