Using PowerShell to Help Clear a ConfigMgr Inbox Backlog

Using PowerShell to Help Clear a ConfigMgr Inbox Backlog

(Originally posted 11/10/2015. Reposting for reference)

 

While working with a client recently, I noticed that the ConfigMgr console was not showing up-to-date information for things like Endpoint Protection status and several other timely sets of data.  Having been through the fun that is Inbox backlogs before, I went ahead and checked to see if there were any file backlogs. I certainly wasn’t about to browse through all of the inbox folders to look for large numbers of files…not when it’s so easy to check with PowerShell.  Here is the command I ran and the results:

    Get-ChildItem “G:\Program Files\Microsoft Configuration Manager\inboxes” -recurse | Where {!$_.PSIsContainer} | Group Directory | Format-Table Name, Count -autosize

OK, safe to say it’s NOT a good thing to see almost half a million files in any of your inboxes.  To help clear out the inboxes, I did the following:

  1. Disabled the SMS_SITE_COMPONENT_MANAGER and SMS_EXECUTIVE services
  2. Rebooted the site server
  3. Renamed the statesys.box\incoming folder to statesys.box\incoming.bak (the \incoming folder will be re-created automatically)
  4. Changed the services back to Automatic and started the services
  5. Verified that the server was stable and processing new incoming state messages, and that SQL wasn’t getting slammed

This left me with a directory containing over 500k files by the time I finally got everything stabilized. All of those files contain information that we do ultimately want to get into the database, but we can’t just drop them all back in the inbox folder at once and expect a good outcome.  So I need to find a way to move them back in in a controlled manner. With that many files, I can’t just navigate to the folder in Windows Explorer select a batch and cut/paste; Explorer isn’t prepared to handle that.  This is where PowerShell once again becomes essential.

The files in this inbox are mostly just .SMX files with a seemingly random eight-character alphanumeric name. 

The statesys.box\incoming folder, seen here in better days

So, alphanumeric gives us 36 easy divisions of that 500k files, which works out to about 14k files each.  Running a quick PowerShell command against the folder verifies that our estimated file count is roughly accurate:

    (Get-ChildItem “G:\Program Files\Microsoft Configuration Manager\inboxes\auth\statesys.box\incoming.bak” -filter “8*.*”).Count

Wtih the server relatively happy again, let’s move a batch of those files into the statesys.box\incoming folder and verify that they will process fine.  We’ll pick a lower number (in this case, files starting with zero) and use the following command to move them:

    Get-ChildItem “g:\Program Files\Microsoft Configuration Manager\inboxes\auth\statesys.box\incoming.bak” -filter 0*.*” | Move-Item -Force -Destination “g:\Program Files\Microsoft Configuration Manager\inboxes\auth\statesys.box\incoming”

After moving the files, we can watch the \incoming and \process folders to verify that they are processing and clearing out. In this case, it only took about a minute or so to process those 6732 files.  Doing another, larger batch took a little under three minutes. 

While running this command another 34 times would provide a wonderful amount of entertainment, I think our time is best spent on other tings. So, let’s set ourselves up with a PowerShell script that will do it for us.  We’ll just create a quick array of all the alphanumeric characters we’re interested in, then loop through that array and move each set of files in. After each move, we’ll give the server five minutes to get caught up before we move each subsequent batch.

Here’s our script:

$arr=@(“a”,“b”,“c”,“d”,“e”,“f”,“g”,“h”,“i”,“j”,“k”,“l”,“m”,“n”,“o”,“p”,“q”,“r”,“s”,“t”,“u”,“v”,“w”,“x”,“y”,“z”,“0”,“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”)
foreach ($n in $arr){
 write-host “Checking number of files with name $n*.*”
 $count=(Get-ChildItem “c:\Program Files\Microsoft Configuration Manager\inboxes\auth\statesys.box\incoming.bak” filter $n*.*”).Count
 if ($count -ne 0){
  write-host “Moving $count files named $n*.* to incoming”
  Get-ChildItem “c:\Program Files\Microsoft Configuration Manager\inboxes\auth\statesys.box\incoming.bak” -filter $n*.*” | Move-Item -Force -Destination “c:\Program Files\Microsoft Configuration Manager\inboxes\auth\statesys.box\incoming”
  start-sleep 300
 }
}

All told, with some adjustments based on server performance I was able to clear out the entire backlog in about half a day.  This is yet another great example of why you need to have at least some working knowledge of PowerShell as a ConfigMgr admin.  It will save you countless hours!

Note – if you copy/paste scripting from this post, make sure you double check the single and double quotes…they don’t always paste correctly and may cause issues.

Leave a Reply

Your email address will not be published. Required fields are marked *