One of my customers asked for a ‘self service tool’ for their users to remove Microsoft APP-V pkg files from their profiles. Because there’s no direct relation between the registry values and the location of the pkg files I had to be creative with a search within this script:
[codesyntax lang=”powershell”]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
#================================================================= # AUTHOR: Kees Baggerman # COMPANY: Inter Access B.v. # DATE: 21-02-2010 # Version: 0.2 # Puts all the app-v applications in an drop down menu # and removes the PKG files from the selected application. #================================================================= if (Test-Path HKLM:\SOFTWARE\Microsoft\Softgrid\4.5\Client\Applications) { # Get all subkeys from HCKU:\ $HKLM = 2147483650 $key = "SOFTWARE\Microsoft\Softgrid\4.5\Client\Applications" $reg = [wmiclass]‘\\.\root\default:StdRegprov’ $subkeys = $reg.EnumKey($HKLM, $key) $subkeys.snames # Put all of the registry keys in an array and put that in a dropdown menu. [array]$DropDownArray = $subkeys.snames # This Function Returns the Selected Value and Closes the Form function Return-DropDown { $Choice = $DropDown.SelectedItem.ToString() $Form.Close() function Get-RegistryValue($key, $value) { (Get-ItemProperty $key $value).$value } $AppName = Get-RegistryValue HKLM:\SOFTWARE\Microsoft\Softgrid\4.5\Client\Applications\$Choice ` AppPath $AppName = $AppName.Substring(1,8) Function FindFolder { $input | Where-Object {$_.Name -match $AppName} } $AppLoc = Get-ChildItem -Path $Env:AppData | FindFolder Remove-Item $Env:AppData\$AppLoc -recurse } [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $Form = New-Object System.Windows.Forms.Form $Form.StartPosition = "CenterScreen" $Form.width = 300 $Form.height = 150 $Form.Text = ”AppVPKGRemover” $DropDown = new-object System.Windows.Forms.ComboBox $DropDown.Location = new-object System.Drawing.Size(100,10) $DropDown.Size = new-object System.Drawing.Size(130,30) ForEach ($Item in $DropDownArray) { $DropDown.Items.Add($Item) } $Form.Controls.Add($DropDown) $DropDownLabel = new-object System.Windows.Forms.Label $DropDownLabel.Location = new-object System.Drawing.Size(10,10) $DropDownLabel.size = new-object System.Drawing.Size(100,20) $DropDownLabel.Text = "Applications" $Form.Controls.Add($DropDownLabel) $Button = new-object System.Windows.Forms.Button $Button.Location = new-object System.Drawing.Size(100,50) $Button.Size = new-object System.Drawing.Size(100,20) $Button.Text = "Remove files" $Button.Add_Click({Return-DropDown}) $form.Controls.Add($Button) $Button1 = new-object System.Windows.Forms.Button $Button1.Location = new-object System.Drawing.Size(100,75) $Button1.Size = new-object System.Drawing.Size(100,20) $Button1.Text = "Quit" $Button1.Add_click({ $form.close() }) $form.Controls.Add($Button1) $Form.Add_Shown({$Form.Activate()}) $Form.ShowDialog() } else { [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $Form = New-Object System.Windows.Forms.Form $Form.StartPosition = "CenterScreen" $Form.width = 300 $Form.height = 150 $Form.Text = ”AppVPKGRemover” # Create the label control and set text, size and location $label = New-Object Windows.Forms.Label $label.Location = New-Object Drawing.Point 100,50 $label.Size = New-Object System.Drawing.Size(125,20) $label.text = "App-V is not installed!" $form.controls.add($label) $Button1 = new-object System.Windows.Forms.Button $Button1.Location = new-object System.Drawing.Size(100,75) $Button1.Size = new-object System.Drawing.Size(100,20) $Button1.Text = "Quit" $Button1.Add_click({ $form.close() }) $form.Controls.Add($Button1) $Form.Add_Shown({$Form.Activate()}) $Form.ShowDialog() } |
[/codesyntax]
A small disclaimer: Powershell and scripting is not my day to day work so it’s possible that this script has a couple of flaws. I did a lot of copy/pasting from a couple of blogs and MS posts but feel free to use this script. It’s a draft version thus I can’t guarantee that this will work but in my test environment it does. If you have additional comments just drop a comment so I can optimize this script.
Kees Baggerman
Latest posts by Kees Baggerman (see all)
- Nutanix AHV and Citrix MCS: Adding a persistent disk via Powershell – v2 - November 19, 2019
- Recovering a Protection Domain snapshot to a VM - September 13, 2019
- Checking power settings on VMs using powershell - September 11, 2019
- Updated: VM Reporting Script for Nutanix with Powershell - July 3, 2019
- Updated (again!): VM Reporting Script for Nutanix AHV/vSphere with Powershell - June 17, 2019
The WMI namespace for App-V has an Application class that you could use to get the App-V apps. This would probably be a little safer than reading registry keys. You could also use this class to get the application’s package GUID, which is the basis for part of the PKG folder name.
For example, to fill in your drop-down box…
$apps = Get-WmiObject -Class “Application” -Namespace “root\microsoft\appvirt\client” |
Sort-Object Name
foreach ($app in $apps)
{
$DropDown.Items.Add([System.String]::Format(“{0}”, $app.Name))
}
[…] This post was mentioned on Twitter by ChaosNL, Kees Baggerman. Kees Baggerman said: @KBaggerman: New post: Microsoft New post: App-V Self service tool http://bit.ly/ftM5ZO #AppV #Microsoft #Pkg […]
Patrick, thanks for your comments but my test enviroment doesn’t support the namespace in combination with the Class application so it will take some time to re-write the script using WMI. I agree that WMI is a bit safer than plain registry keys.