Clear ccm cache ps script

Hello everyone :

when executing this script on a local machine it clears the ccm cache :

Initialize the CCM resource manager com object

[__comobject]$CCMComObject = New-Object -ComObject ‘UIResource.UIResourceMgr’## Get the CacheElementIDs to delete
$CacheInfo = $CCMComObject.GetCacheInfo().GetCacheElements()## Remove cache items
ForEach ($CacheItem in $CacheInfo) {
$null = $CCMComObject.GetCacheInfo().DeleteCacheElement([string]$($CacheItem.CacheElementID))
}

but not when deploying by sccm, any suggestions or other scripts ?