I was doing some puttering on the laptop this morning. From time to time I run a utility called WinDirStat which is a good way to find large amounts of wasted disk space.

So I noticed that C:\Windows\System32\FileRepository was eating up 17GB of disk space. I thought there must be a way to trim this up. From what I understand from doing some research this is a necessary store for drivers that are in use. But it tends to collect all the driver detritis your system downloads and may have used, or not. I'm not entirely clear on that part.

Windows doesn't appear to have any UI for cleaning these out, and doing the brute force of nuking the files in the folder could have unintended consequences.

Fortunately there is a way to remove unused drivers safely though! It just requires a little bit of powershell scripting.

pnputil /enum-drivers | Select-String -Pattern "^*.(?<driver>oem.*)" | %{ $_.Matches[0].Value.Trim(
) } | %{ pnputil /delete-driver $_}


You can run the above script and sweet, you'll save all the GBs! My system went from ~17GB of usage in this folder to 1GB. pnputil will not remove drivers in use, so some messages where it couldn't remove a driver are expected.

Breaking it down

pnputil is built into Windows and has a few things that are very useful for what we are trying to accomplish, like enumerating the drivers in the store.

pnputil /enum-drivers
Sample output:

Microsoft PnP Utility

Published Name:     oem31.inf
Original Name:      heci.inf
Provider Name:      Intel
Class Name:         System devices
Class GUID:         {4d36e97d-e325-11ce-bfc1-08002be10318}
Driver Version:     08/31/2015
Signer Name:        Microsoft Windows Hardware Compatibility Publisher

Ok, so now we know the name of the driver files. This output will be quite lengthy.
The next part is we want to extract the oem*.inf names from the output of pnputil

Lets pipe the output from pnputil /enum-drivers into Select-String

pnputil /enum-drivers | Select-String -Pattern "^*.(?<driver>oem.*)"

Example Output:

Published Name:     oem59.inf
Published Name:     oem104.inf
Published Name:     oem31.inf

Next, we need to get the matches, Select-String returns and array of MatchInfo powershell objects.

NOTE: %{} is short hand for Foreach-Object

pnputil /enum-drivers | Select-String -Pattern "^*.(?<driver>oem.*)" | %{ $_.Matches[0].Value.Trim(
) }

Example output:


Now we have a list of strings that are just the driver names we want to attempt to remove from the system.

Just pipe the output above into pnputil /delete-driver

| %{ pnputil /delete-driver $_}

BOOM less disk space used