Skip to content

Instantly share code, notes, and snippets.

@lukemurraynz
Last active December 22, 2016 19:38
Show Gist options
  • Save lukemurraynz/4bb2b67bae79372bb785850106945ef6 to your computer and use it in GitHub Desktop.
Save lukemurraynz/4bb2b67bae79372bb785850106945ef6 to your computer and use it in GitHub Desktop.
App-V Discovery Script
#App-V Discovery Script for SCCM Configuration Baseline
#requires -Modules AppvClient
#requires -Version 2.0
$Now = Get-Date
$Days = 30
$TargetFolder = "$env:ProgramData\App-V"
$LastAccessTime = $Now.AddDays(-$Days)
$Files = Get-ChildItem -Path $TargetFolder | Where-Object -FilterScript {
$_.LastAccessTime -lt "$LastAccessTime"
}
$null = @()
if ($Files.count -gt 0)
{
Write-Host 'Non-Compliant'
}
else
{
Write-Host 'Compliant'
}
#App-V Remediation Script for SCCM Configuration Baseline
#requires -Modules AppvClient
#requires -Version 2.0
Start-Transcript -Path c:\temp\"$env:COMPUTERNAME".log
$Now = Get-Date
$Days = 30
$TargetFolder = "$env:ProgramData\App-V"
$LastAccessTime = $Now.AddDays(-$Days)
$Files = Get-ChildItem -Path $TargetFolder | Where-Object -FilterScript {
$_.LastAccessTime -lt "$LastAccessTime"
}
$null = @()
if ($Files.count -gt 0)
{
foreach ($null in $Files)
{
$Result = Get-AppvClientPackage | Where-Object { $_.Name -notlike 'Microsoft App-V 5.0*'} -Verbose
foreach ($PackageId in $Result)
{
Get-AppvClientPackage -PackageID $PackageId.PackageID.Guid | Remove-AppvClientPackage -Verbose
}
foreach ($null in $TargetFolder)
{
Get-ChildItem -Path $TargetFolder | Where-Object {$_.PSIsContainer -eq 'True' -and $_.GetFileSystemInfos().Count -eq 0} | Remove-Item -Verbose
}
}
}
Stop-Transcript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment