Tuesday 6 March 2018

PowerShell: Script to remove AppV application with name.

Created an Universal remover script for AppV, which is used to remove an AppV application with use of application name.

Script:

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$Name = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Package Name", "APPV:Universal Remover", "")
$logfile="C:\Windows\Logs\"+$Name+".log"
Import-Module AppvClient
$package=Get-AppvClientPackage -All|?{ $_.Name -like "*$Name*"}
if($package)
{
$package|ForEach-Object{
    $Name1=$_.Name
    $a = new-object -comobject wscript.shell
    $intAnswer = $a.popup("Do you want to remove $Name1 application?", 0,"Uninstall",4)
    If ($intAnswer -eq 6) {  
    Stop-AppvClientPackage "$Name1"|Unpublish-AppvClientPackage -Global|Remove-AppvClientPackage | Out-File -Append -FilePath $logfile
    }
    }
}
else{
    Write-Host "Package named like($Name) is not published in the machine"
    }

Steps To DO:
1. Copy code and save the script as XXX.PS1
2. Set the execution policy to run the script.
3. Execute the script and you will get popup for application name. Enter the application name to uninstall and click OK.

4. Click Yes.
 
5.Application will get removed form system.(if you have multiple applications with related to given  name, you will get all the applications one after other to proceed for removing)

Note: Application will get removed successfully for all users, if any error occurs kindly check the event viewer logs for more details.

No comments:

Post a Comment