Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornhouben committed May 27, 2018
1 parent c60b482 commit 9d21a7b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Clear-SccmCache.ps1
@@ -0,0 +1,25 @@
#$ComputerNames = Import-Csv -Path 'C:\Beheer\Scripts\Servers.csv' -Delimiter ','
$ComputerNames = Get-ADComputer -filter * -Properties OperatingSystem,LastLogonDate | Where{($_.OperatingSystem -match 'Server') -and ($_.LastLogonDate -ge (Get-Date).AddDays(-90))} | Select-Object -ExpandProperty Name

$Output=@()
Foreach($ComputerName in $ComputerNames)
{
Write-Output "Started task to clear SCCM cache $Computername"
$FreeSpaceInGBBefore = Invoke-Command -ComputerName $ComputerName -Scriptblock {[MATH]::Round(((Get-WmiObject win32_volume | Where{$_.Name -eq 'C:\'} | Select -ExpandProperty Freespace)/1GB),2)}
$Scriptblock = { #Code to empty the SCCM Cache
$UIResourceMgr = New-Object -ComObject UIResource.UIResourceMgr
$Cache = $UIResourceMgr.GetCacheInfo()
$Cache.GetCacheElements() <#| Where-Object{$_.LastReferenceTime -gt (Get-Date).adddays(-14)}#> | foreach {$Cache.DeleteCacheElement($_.CacheElementID)}
}
Invoke-Command -ComputerName $ComputerName -ScriptBlock $ScriptBlock -ErrorAction SilentlyContinue | Out-Null
$FreeSpaceInGBAfter = Invoke-Command -ComputerName $ComputerName -Scriptblock {[MATH]::Round(((Get-WmiObject win32_volume | Where{$_.Name -eq 'C:\'} | Select -ExpandProperty Freespace)/1GB),2)}
$Object=[PSCUSTOMOBJECT][ORDERED]@{
'Computername' = $ComputerName
'FreeSpaceInGBBefore' = $FreeSpaceInGBBefore
'FreeSpaceInGBAfter' = $FreeSpaceInGBAfter
}
$Object
$Output += $Object
Write-Output "Stopped task to clear SCCM cache $Computername"
}
$Output

0 comments on commit 9d21a7b

Please sign in to comment.