问题描述:

I am trying to create a script that removes a certain AppV package. The problem I am having is the AppV package is installed under the local user which does not have admin access so I get this message:

"Permission denied"

However, when I run the script as administrator and give my credentials, the AppV package does not show up. Here is the section of code I am using to list and remove the package.

# Remove AppV version of inProcess

$allAppV = Get-AppvClientPackage

If ($allAppV.Count -ge 0) {

$i = 1

#This part lists the packages

Write-Host "List AppV packages"

ForEach($Package in $allAppV) {

Write-Host `t $i - $Package.Name

$i +=

1

}

# Select which package to remove

$NumbertoRemove = Read-Host

"Which one would you like to remove? Type 0 if none"

If ($NumbertoRemove -eq 0) {

Write-Host "Not removing any App-V Client Package"

$Global:More = $False

}

else {

If ($NumbertoRemove -le $allAppV.Count) {

$NumbertoRemove -= 1

Write-Host "Removing package" $allAppV[$NumbertoRemove].Name

$PackageToRemove = $allAppV[$NumbertoRemove]

If ($PackageToRemove.IsPublishedGlobally)

{Unpublish-AppvClientPackage $allAppV[$NumbertoRemove]}

# I need to provide admin credentials for this step

Remove-AppvClientPackage $allAppV[$NumbertoRemove]

Write-Host "AppV Client Package has been removed"

This is what it looks like when I run the script as the local user. If I enter 1 it will try to remover inProcess but gets permission denied error.

If I run as administrator it looks the same except it lists no packages. I imagine because the script is running as administrator so it is listing packages installed under the admin account which their are none.

I need to either run the script as administrator but list the Appv packages of the local user or provide credentials for the remove-AppvClientPackages step. It would be preferable to prompt for credentials to remove the package. Thanks

网友答案:

Use the Get-AppvClientPackage cmdlet with the -All switch, this will list all AppV packages on the computer regardless of the current user. You will still need to run the cmdlet with administrative credentials to uninstall the package.

$allAppV = Get-AppvClientPackage -All
相关阅读:
Top