Friday, February 17, 2017

Remove all unpublished apps to clear package cache

Often I see queries related to clearing leftover package files after unpublishing them. And so here is a sample powershell code to remove all unpublished packages from the system to clear the space they were occupying in the package store.


$allpackages= Get-AppvClientPackage -all|Where-Object {$_.IsPublishedToUser -like "False" -and $_.IsPublishedGlobally -like "False"} | select Name

 $unpublished=$allpackages.name

 ForEach($package in $unpublished)

 {

Write-Host "$package"

Remove-AppvClientPackage "$package"

Write-Host "$package" removed.

 }

NOTE: Test the code in a lab environment, as it doesn't support any error handling.