Skip to content

Instantly share code, notes, and snippets.

Created April 28, 2017 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d7dd57c6f4b1dd0c412fdd4638d63bc7 to your computer and use it in GitHub Desktop.
Save anonymous/d7dd57c6f4b1dd0c412fdd4638d63bc7 to your computer and use it in GitHub Desktop.
App-VRepairClientCache
#-----------------------------------------------------------------------#
# Scriptname: App-vRepairClientCache #
# Creator: Matthias Meißner - Login Consultants Germany GmbH #
# Date: 2017/04/13 #
# Actual Ver.: 0.0.0.4 #
# Version History: #
# 0.0.0.1 MM Initial Version by Matthias Meißner #
# 0.0.0.2 MM Add Remove-AllPermissions Function #
# 0.0.0.3 MM Add Foreach-Loop to read Data from CSV #
# 0.0.0.4 MM Add Foreach-Loop and Read WMI to delete users Cache #
#-----------------------------------------------------------------------#
# Description: #
# Script is reading CSV File including Server FQDN and reset ACL for #
# App-V Client Cash to delete cash. #
#-----------------------------------------------------------------------#
# CSV File must be located in same directory as the running script and must be structured like this:
#
# Servername
# Server1
# Server2
# ......
#Declare Variables (you have to configure the following two Variables to meet requirements of your own infrastructure)
$Username = 'Domainname\executionAccountname'
$KnownFolders = 'App-VCachefolder'
#Import App-V Module
Import-Module “C:\Program Files\Microsoft Application Virtualization\Client\AppvClient\AppvClient.psd1”
#Import CSV
$Servers = Import-CSV '.\Import.csv' -Delimiter ';'
#Run Remote Powershell Command for each Server defined in CSV
foreach ($Servername in $Servers) {
$takename = $Servername.Servername
Invoke-Command -ComputerName $takename -ScriptBlock {
Function Remove-AllPermissions () {
Param(
$Folders
)
BEGIN {
$FunctionName = $myinvocation.mycommand.name
Write-Host "$FunctionName - Removes permissions from given directory - START"
}
PROCESS {
$acls = Get-Acl -path $folders
$outputObject = @()
Write-Host "$FunctionName - removing permissions from folder $Folders"
Foreach($acl in $acls) {
$folder = (convert-path $acl.pspath)
Foreach($access in $acl.access) {
$acl.RemoveAccessRule($access) | Out-Null
} # end foreach access
Set-Acl -path $folder -aclObject $acl
$i++
}
}
end{Write-Host "$FunctionName - Removes permissions from given directory - Finish"}
}
Write-Host 'Permissions will be set....:'
Remove-AllPermissions ($KnownFolders)
Write-Host 'Stopping App-V Client Service....'
net stop AppVClient
Write-Host 'Remove Client Packages....'
Get-AppvClientPackage -All | Remove-AppVClientPackage
Write-Host 'Stopping App-V Client Service....'
net stop AppVClient
Write-Host 'Delete Registry Hive: HKLM:\SOFTWARE\Microsoft\AppV\Client\Packages'
Remove-Item -Path HKLM:\SOFTWARE\Microsoft\AppV\Client\Packages -force -recurse
Set-Location -Path env:
Write-Host 'Removing App-V5 Client Cache directory'
Remove-Item ($KnownFolders + '*') -recurse
Write-Host 'Get all user accounts loaded locally...'
$loggedonUsers = Get-WmiObject -Class Win32_UserAccount
foreach ($Name in $loggedonUsers) {
$handleuser = $Name.Name
Write-Host "User AppData for User '$handleuser' will be deleted"
$beginningstring = 'C:\Users\'
$UserAppData = $beginningstring + $handleuser + '\AppData'
$PathCatalog = "$UserAppData\Roaming\Microsoft\AppV\Client\Catalog\Packages"
$PathRoamingVFS = "$UserAppData\Roaming\Microsoft\AppV\Client\VFS"
$PathINT = "$UserAppData\Local\Microsoft\AppV\Client\Integration"
$PathClientVFS = "$UserAppData\Local\Microsoft\AppV\Client\VFS"
if (Test-Path $PathCatalog){
Write-Host "Deleting the App-V Catalog Path for User $handleuser"
$PathCatalogfinal = $PathCatalog + '\*'
Remove-Item $PathCatalogfinal -recurse
} else { Write-Host "Path to App-V Catalog for User $handleuser does not exist"}
if (Test-Path $PathRoamingVFS){
Write-Host "Deleting the App-V Roaming VFS Path for User $handleuser"
$PathRoamingVFSfinal = $PathRoamingVFS + '\*'
Remove-Item $PathRoamingVFSfinal -recurse
} else { Write-Host "Path to App-V Roaming VFS for User $handleuser does not exist"}
if (Test-Path $PathINT){
Write-Host "Deleting the App-V Integration Path for User $handleuser"
$PathINTfinal = $PathINT + '\*'
Remove-Item $PathINTfinal -recurse
} else { Write-Host "Path to App-V Integration for User $handleuser does not exist"}
if (Test-Path $PathClientVFS){
Write-Host "Deleting the App-V Client VFS Path for User $handleuser"
$PathClientVFSfinal = $PathClientVFS + '\*'
Remove-Item $PathClientVFSfinal -recurse
} else { Write-Host "Path to App-V Client VFS for User $handleuser does not exist"}
}
Write-Host 'Starting App-V Client Service....'
net start AppVClient
Write-Host 'Get App-V Publishing Server and starting sync....'
Get-AppvPublishingServer | Sync-AppvPublishingServer
} -credential $Username
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment