SCCM ADRs failing to run (Error: 0x80070050)

In this short post, I'm going to be exploring an issue I had at a customer site whereby all ADR's started to fail with error 0x80070050. Nothing had changed (that I was aware of) on the machine or in the environment.

Issue

As mentioned above, all Automatic Deployment Rules (ADR) in the customer's SCCM instance started to fail suddenly. 0x80070050 was reported as the error code.

Investigation

0x80070050 means nothing to me. We need more information to figure out what the issue is, so let's check the logs. The log file we're interested in is PatchDownloader.log (in this case they were in C:\Program Files\SMS_CCM\Logs but you may find them elsewhere).

In the logs I found:
Failed to create temp file with GetTempFileName() at temp location C:\Windows\TEMP, error 80
ERROR: DownloadUpdateContent() failed with hr=0x80070050

Strange... Let's try creating a file in C:\Windows\TEMP. Worked as expected. Permissions issue? Nope, permissions looked absolutely fine. I did notice that the folder took a fairly long time to load and that there were 65k items in there.

I then noticed that the files were indeed being created as they should but SCCM was still reporting that it was unable to create any files in C:\Windows\TEMP. I guessed this was some sort of timeout issue where SCCM was checking if the file had been created successfully and was timing out. I cleared a bunch of files in C:\Windows\TEMP and the errors stopped almost immediately. Checked the ADR a short time later and it was now reporting as "Success".

There were 65k .TMP files with names like below and all zero-byte files before I cleaned them out.

Solution

If you are facing the same errors shown above then the quickest fix is to clear down files in C:\Windows\TEMP. I suggest clearing down the zero-byte files beginning CAB* if they appear. It seems to break around the 65k mark so I'd advise clearing enough to take you significantly below 65k files in the folder and ideally install KB4600089 as per the prevention steps below.

If you want to do this using PowerShell you can run something like the command below in the C:\Windows\TEMP folder and it will delete any 0B files beginning "CAB":

Get-ChildItem -Path "C:\Windows\TEMP\" -File | where {$.Length -eq 0mb -and $.Name -like "CAB*"} | Remove-Item -Force

Prevention

According to the Update Rollup for 2010 (Update Rollup for Microsoft Endpoint Configuration Manager current branch, version 2010) this is fixed in KB4600089 with the following appearing in the list of fixed issues:

"Processing of Automatic Deployment Rules fails after updating to Configuration Manager version 2010. The Last Error Description reads "Auto Deployment Rule download failed". This occurs due to zero-byte temporary files left in the Windows\Temp folder during the download process."

I haven't yet tested this update but I'm assuming this stops the creation of the zero-byte files in the first place, rather than fixing the "Failed to create temp file with GetTempFileName()" when there are 65k files in the directory.

If you can't install this update (KB4600089) for any reason then I would suggest scripting the deletion of the files and scheduling the Powershell one-liner shown above as a Scheduled Task.