Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

PENDING How to run vbs script using SCCM

ken_chiro11

New Member
Messages
2
Reaction score
0
Points
1
Hi Sccm team
I research and modifly Script Clean Folder ccmcache old 30 Day
How to run from sccm when client Status is online (Check everyday when client online)?
This Script .Vbs >>


Dim objFSO
Dim objFolder
Dim objSubFolder
Dim winsh
Dim winenv

'deletes folders with a date modified of 30 day or older
Const intDaysOld = 30
set winsh = CreateObject("WScript.Shell")
set winenv = winsh.Environment("Process")
windir = winenv("WINDIR")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'looks for c:\Windows\ccmcache for 32bit
if objFSO.FolderExists (windir & "\ccmcache") Then
Set objFolder = objFSO.GetFolder(windir & "\ccmcache")
For Each objSubFolder In objFolder.SubFolders
If objSubFolder.DateLastModified < DateValue(Now() - intDaysOld) Then
objSubFolder.Delete True
End If
Next
Wscript.quit
End if
'looks for c:\Windows\ccmcache for 64bit
if objFSO.FolderExists (windir & "\ccmcache") Then
Set objFolder = objFSO.GetFolder(windir & "\ccmcache")
For Each objSubFolder In objFolder.SubFolders
If objSubFolder.DateLastModified < DateValue(Now() - intDaysOld) Then
objSubFolder.Delete True
End If
Next
End if

Thanks
 
BTW, looking at the script, this is NOT a supported method to clear the cache, you need to use the CM functions to do this, otherwise you are leaving WMI populated with extra junk. Why not just force the cache to clear everything? aka why worry about just 30 day old stuff?
 
Back
Top