Some of our older servers are running out of disk space on C:, so I needed to change the SCCM cache directory to D:. By default, this is where I wanted it anyway on our servers, leaving C: only for OS-related files. My OSD Task Sequences all have SMSCACHEDIR set to a folder on D in the client configuration step, but I noticed it wasn’t actually working. You know I had to find a way to fix that using powershell :D It actually ended up being really REALLY easy to do…


It’s a simple WMI query that applies a variable for the cache directory & size (either one, both, doesn’t matter, you choose).

**DISCLAIMER: For location, you do not want a trailing backslash “\” in the path, it will bork your advertisements and the path will end up with double backslashes, like D:\path\to\cache\\advID. I learned this the hard way.

I ended up creating different scripts, one to integrate into my OSD Task Sequence that simply does the following:

$ccmcfg = Get-WmiObject -Namespace root\ccm\SoftMgmtAgent -Class CacheConfig
$ccmcfg.Location = "d:\path\to\cache"
$ccmcfg.Size = "2048"
$ccmcfg.Put()

This is designed to run directly on the SCCM Client machine. I also have it set the cache size to 2GB. In my OSD Task Sequence, I put a reboot after this step so the agent runs with the new settings.

I have another that is designed to target computers based on SCCM Computer Collection:

$ColQuery = "select * from sms_cm_res_coll_SMS0005E"
 
$CollectionMembers = gwmi -computername SCCM_Server -namespace root\sms\site_SMS -Query $ColQuery |sort Name
 
foreach($comp in $collectionmembers){
    $server = $comp.name
    write-host -fore green `n`t "working on " $server
    $ccmcfg = gwmi -computer $server -Namespace root\ccm\SoftMgmtAgent -Class CacheConfig
    $ccmcfg.Location = "d:\path\to\cache"
    $ccmcfg.Size = "2048"
    $ccmcfg.Put()
 
    #stop service, sleep for 10s, start the service
    Get-Service -computer $server ccmexec | Stop-Service
    Start-Sleep 10
    Get-Service -computer $server ccmexec | Start-Service
 
    write-host -fore green `n`t "finished" $server
}

This is designed to be ran from any machine that has network access to both the SCCM server and the SCCM clients. You’d need to change a few things for it to work in your environment, however, I’m sure you can figure it out.

I also added logic to validate D: even exists (it doesn’t on some of ours, so it quits, leaving default values), and validate the folder exists (create it if not). This is the end result that is a task in my OSD Task Sequence, it shows current config, sets the new config, then shows us the new config. Notice there’s no restart of the agent? That’s because it’ll fool SCCM into thinking the server rebooted unexpectedly and we don’t want that.

#first lets check to make sure D exists
if ((Test-Path d:) -eq $True){
 
    #now lets check if the directory itself exists, create if it doesnt
    if (!(test-path d:\path\to\cache\)){write-host "cache dir does not exist, creating"; md d:\path\to\cache\}
 
    #pull the config
    $ccmcfg = Get-WmiObject -Namespace root\ccm\SoftMgmtAgent -Class CacheConfig
    write-host "current config"
    $ccmcfg
 
    #set config location, size, and write to wmi
    $ccmcfg.Location = "d:\path\to\cache"
    $ccmcfg.Size = "2048"
    $ccmcfg.Put()
 
    #show current config
    $ccmcfg = Get-WmiObject -Namespace root\ccm\SoftMgmtAgent -Class CacheConfig
    write-host "new config"
    $ccmcfg
}
 
#Let us know if D isn't there
else{write-host "D drive doesn't exist"}