MEM-Zone / MEM.Zone

Our ♡ collection of PowerShell scripts and Endpoint Management related stuff 🐵
https://MEM.Zone/GIT
GNU General Public License v3.0
97 stars 10 forks source link

[BUG] - Running Invoke-CCMCacheCleanup as SCCM package #20

Open mbradley73 opened 1 month ago

mbradley73 commented 1 month ago

Describe the bug Trying to run the Invoke-CCMCacheCleanup script as a package in SCCM and getting a failure (message ID error 10006).

To Reproduce This is the command I'm using: %SystemRoot%\SysNative\WindowsPowerShell\v1.0\PowerShell.exe -ExecutionPolicy Bypass -NoProfile -WindowStyle Hidden -File Invoke-CCMCacheCleanup.ps1 -CacheType "Orphaned" -CleanupType "Tombstoned"

Expected behavior For the script to clean complete with no errors and ccmcache be rid of orphaned packages.

Ioan-Popovici commented 1 month ago

Hi, You should not try to run it as a package because you are not installing anything. Please run it as a configuration baseline as specified. The error you specified is a generic error and you would need to check the execution logs to see what exactly went wrong.

If you run it as a detection script, you don't need a remediation script. You also need to suppress all output for this to work.

CleanShot 2024-08-14 at 15 52 35@2x

mbradley73 commented 1 month ago

I often use package to run PowerShell scripts that don't need to install anything, so I was trying to do that same thing here. Being that the script requires more than just the file name, and needs various parameters, how do you do that in a baseline? I can only select a script to run in a CI, but don't see a way to set the parameters (like for orphaned content).

Further troubleshooting this, running it manually on my machine, with this command line: .\Invoke-CCMCacheCleanup.ps1 -CacheType "Orphaned" -CleanupType "Tombstoned" , I get this error: Script initialization failed. Cannot validate argument on parameter 'ScriptSection'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At C:\clean\Invoke-CCMCacheCleanup.ps1:1766 char:5

Ioan-Popovici commented 4 weeks ago

Yeah, I get it, but if there's no payload, why use packages?

In a CI you just have to change the default parameters. I'll make a blog post in the future.

Try the new version here

I don't know if it fixes it entirely, but it will fix the error you get so we can see what else is wrong.

The Tombstoned parameter should not be used with Orphaned because it doesn't make sense. The orphaned cache is not supposed to be there because it has no links with the caching system. I overlooked this when creating the script.

Please try to run the script manually with Tombstoned and All and report the result.

Thanks Ioan

mbradley73 commented 3 weeks ago

Sorry, I was going off the script comments that in the example appeared to include both of those conditions in the command. I've now tried this: Invoke-CCMCacheCleanup.ps1 -CleanupType "Tombstoned" , and it resulted in no errors, but didn't remove anything either. Are orphaned and tombstoned the same thing? Running just Invoke-CCMCacheCleanup.ps1 (which defaults to the All condition I think, right?), worked, deleting almost everything.

Thank you for you assistance on this, it is much appreciated.

Ioan-Popovici commented 3 weeks ago

So there is a parameter issue.

Tombstoned means items that have passed the cache expiration date an can safely be deleted

Orphaned means wmi items that have no links on disk or disk items that have no links in wmi

I'll add a parameter check and explain these things better on the blog page.

Thanks Ioan