‎04-16-2024 04:05 PM - last edited on ‎04-17-2024 10:08 AM by Mercedes_O
We use SCCM to deploy packages so we needed to monitor the c:\windows\ccmcache folder. We have a 10 GB policy on that folder so it is not supposed to get over 10 gigs. BUT we have many workstations that are over 20, 40 and even 60 gigs. That had me thinking... How can I get a report on each and every device's ccmcache folder size. A few discussions around her helped me get the report I needed. Here is what I did..
Create a powershell script that gets the folder size, converts the size and rounds it up to only two decimals and then writes that value to a custom registry key.
Here is the script I used. Push this powershell script however you can, having it run at startup would be best. That way the key value is consistently updated.
# Define the folder path
# Change the patch to the folder you would like to monitor
$FolderPath = "C:\Windows\ccmcache"
# Get the folder size in bytes
# Do not change anything on this line
$FolderSizeBytes = (Get-ChildItem -Path $FolderPath -Recurse | Measure-Object -Property Length -Sum).Sum
# Convert bytes to gigabytes and round to two decimal places
# Do not change anything on this line
$FolderSizeGB = [Math]::Round($FolderSizeBytes / 1GB, 2)
# Format the gigabytes value to include leading zero for single digits
$FormattedSize = "{0:00.00}" -f $FolderSizeGB
# Creates a reg path with Your Companys Name
# Change the YOURCOMPANYNAME to whatever you like
$RegistryPath = "HKLM:\SOFTWARE\YourCompanyName"
# Created a reg string name for the folder being monitored
# Change the name inside the "" to whatever you like
$RegistryName = "CCMCACHESIZE"
# Check if the registry key exists
# Do not change anything on these lines
if (-not (Test-Path $RegistryPath)) {
New-Item -Path $RegistryPath -Force | Out-Null
}
# Set or update the registry value
# Do not change anything on this line
Set-ItemProperty -Path $RegistryPath -Name $RegistryName -Value $FolderSizeGB -Force
After running the script you should now see the new registry key and value like this.
Now that is done we need to setup Lansweeper to scan that registry key.
In Lansweeper go to "Scanning" --> "File & Registry Scanning"
Under "Registry Scanning" Click "Add Registry Scan.
Now you should see that key in the Registry Scanning
------------------------------------------------------------------------------------------------------------------------------
Now you can see that value on each device or in a report.
To see information for each device -
To see the value on each device, go to that device's page --> Click Config --> Scanned Items --> Registry Keys.
You will see the newly scanned registry key.
To run a report for the registry key value.
All you need to do is create a new report with the following...
Select Top 1000000 tblAssets.AssetID,
tblAssets.AssetName,
tblAssets.Domain,
tblAssets.Username,
tblAssets.Userdomain,
Coalesce(tsysOS.Image, tsysAssetTypes.AssetTypeIcon10) As icon,
tblAssets.IPAddress,
tsysIPLocations.IPLocation,
tblAssetCustom.Manufacturer,
tblAssetCustom.Model,
tsysOS.OSname As OS,
tblAssets.Version,
tblAssets.SP,
Case
When TsysLastscan.Lasttime < GetDate() - 1 Then
'Last registry scan more than 24 hours ago! Information may not be up-to-date. Try rescanning this machine.'
End As Comment,
Case
When SubQuery1.Valuename Is Not Null And SubQuery1.Valuename <> ''
Then 'Yes'
Else 'No'
End As ValuenameFound,
SubQuery1.Regkey,
SubQuery1.Valuename,
SubQuery1.Value,
Case
When tblErrors.ErrorText Is Not Null Or
tblErrors.ErrorText != '' Then
'Scanning Error: ' + tsysasseterrortypes.ErrorMsg
Else ''
End As ScanningErrors,
TsysLastscan.Lasttime As LastRegistryScan,
SubQuery1.Lastchanged,
tblAssets.Firstseen,
tblAssets.Lastseen,
tblAssets.Lasttried
From tblAssets
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
Inner Join tsysIPLocations On tsysIPLocations.LocationID =
tblAssets.LocationID
Inner Join tblState On tblState.State = tblAssetCustom.State
Left Join tsysOS On tsysOS.OScode = tblAssets.OScode
Left Join (Select Distinct Top 1000000 tblErrors.AssetID As ID,
Max(tblErrors.Teller) As ErrorID
From tblErrors
Group By tblErrors.AssetID) As ScanningError On tblAssets.AssetID =
ScanningError.ID
Left Join tblErrors On ScanningError.ErrorID = tblErrors.Teller
Left Join tsysasseterrortypes On tsysasseterrortypes.Errortype =
tblErrors.ErrorType
Inner Join TsysLastscan On tblAssets.AssetID = TsysLastscan.AssetID
Inner Join TsysWaittime On TsysWaittime.CFGCode = TsysLastscan.CFGcode
Left Join (Select Top 1000000 tblRegistry.AssetID,
tblRegistry.Regkey,
tblRegistry.Valuename,
tblRegistry.Value,
tblRegistry.Lastchanged
From tblRegistry
Where tblRegistry.Regkey Like 'HKEY_LOCAL_MACHINE\SOFTWARE\YourComanyName'
And tblRegistry.Valuename = 'CCMCACHESIZE') SubQuery1 On
SubQuery1.AssetID = tblAssets.AssetID
Where tblAssetCustom.State = 1 And TsysWaittime.CFGname = 'registry'
Order By tblAssets.Domain,
tblAssets.AssetName
Solved! Go to Solution.
‎04-16-2024 07:23 PM
No prob. Hopefully this will help someone else trying to do the same.
Also.. I updated the PS script to show the gigabytes value to include leading zero for single digits. This really helps when trying to sort by numbers. So you shouldn't see things like this...
‎04-16-2024 07:23 PM
No prob. Hopefully this will help someone else trying to do the same.
Also.. I updated the PS script to show the gigabytes value to include leading zero for single digits. This really helps when trying to sort by numbers. So you shouldn't see things like this...
‎04-16-2024 05:29 PM
Hello there!
Awesome work! 😎 Thanks for sharing!
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now