FileRepository data store

Removing Old and Unused Drivers from Driver Store using Powershell

Each time you install or update your device driver, Windows OS (since Vista) continues to store the old version of the driver in the system Driver Store. Thereby, if the system doesn’t work correctly with the new driver, user can roll back to an older version of the driver at any moment.

Windows Driver Store is located in the folder C:\windows\system32\DriverStore\FileRepository. However, some Windows users began to notice that over time, the folder %windir%\system32\DriverStore\FileRepository begins to occupy more and more disk space. In our example, the size of this folder is more than 11 GB. Quite a lot, especially for the SSD drive!


How to Remove Old and Unused Drivers from Driver Store?

To clear the contents of folder FileRepository from the outdated drivers, we prepared a small PowerShell script, that removes all duplicates drivers except the drivers with the latest date.

Warning! In any case don’t delete any files or folders manually from the directory FileRepository!

Important Tips:

  • To run this script you need to update your PowerShell version to Windows Management Framework 1 (or at least WMF4).
  • Before running the script, make sure you have the current drivers for the video card, printer and other devices, that are constantly in use. In case of problems, you can always re-install properly driver.
  • Also it is recommended to create a restore point. To do this, run the command:
    Checkpoint-Computer -Description “PointBeforeDeleteUnusedDrivers”

    Verify that the restore point was created successfully using the command:


We will get the list of third-party drivers installed in the system by using the DISM command:

dism /online /get-drivers

Then parse the output using PowerShell, select the driver duplicates and sort them by date. From the resulting list we will exclude the most recent version for each driver.

After that, remove remaining drivers using pnputil utility. In some cases, if some driver is not removed, add the -f switch.

The script is as follows:

$dismOut = dism /online /get-drivers

$Lines = $dismOut | select -Skip 10

$Operation = "theName"

$Drivers = @()

foreach ( $Line in $Lines ) {

    $tmp = $Line

    $txt = $($tmp.Split( ':' ))[1]

    switch ($Operation) {

        'theName' { $Name = $txt

                     $Operation = 'theFileName'



        'theFileName' { $FileName = $txt.Trim()

                         $Operation = 'theEntr'



        'theEntr' { $Entr = $txt.Trim()

                     $Operation = 'theClassName'



        'theClassName' { $ClassName = $txt.Trim()

                          $Operation = 'theVendor'



        'theVendor' { $Vendor = $txt.Trim()

                       $Operation = 'theDate'



        'theDate' { # change the date format for easy sorting

                     $tmp = $txt.split( '.' )

                     $txt = "$($tmp[2]).$($tmp[1]).$($tmp[0].Trim())"

                     $Date = $txt

                     $Operation = 'theVersion'



        'theVersion' { $Version = $txt.Trim()

                        $Operation = 'theNull'

                        $params = [ordered]@{ 'FileName' = $FileName

                                              'Vendor' = $Vendor

                                              'Date' = $Date

                                              'Name' = $Name

                                              'ClassName' = $ClassName

                                              'Version' = $Version

                                              'Entr' = $Entr



                        $obj = New-Object -TypeName PSObject -Property $params

                        $Drivers += $obj



         'theNull' { $Operation = 'theName'





Write-Host "All installed third-party  drivers"

$Drivers | sort Filename | ft

Write-Host "Different versions"

$last = ''

$NotUnique = @()

foreach ( $Dr in $($Drivers | sort Filename) ) {


    if ($Dr.FileName -eq $last  ) {  $NotUnique += $Dr  }

    $last = $Dr.FileName


$NotUnique | sort FileName | ft

Write-Host "Outdated drivers"

$list = $NotUnique | select -ExpandProperty FileName -Unique

$ToDel = @()

foreach ( $Dr in $list ) {

    Write-Host "duplicate found" -ForegroundColor Yellow

    $sel = $Drivers | where { $_.FileName -eq $Dr } | sort date -Descending | select -Skip 1

    $sel | ft

    $ToDel += $sel


Write-Host "Drivers to remove" -ForegroundColor Red

$ToDel | ft

# removing old drivers

foreach ( $item in $ToDel ) {

    $Name = $($item.Name).Trim()

    Write-Host "deleting $Name" -ForegroundColor Yellow

    Write-Host "pnputil.exe -d $Name" -ForegroundColor Yellow

    Invoke-Expression -Command "pnputil.exe -d $Name"


Tip. In case you need to show the list of unused drivers only, comment Invoke-Expression (add a # character before the command Invoke-Expression -Command “pnputil.exe -d $Name)

Copy the code of the script and save it to file drv_cleanup.ps1 (to the folder c:\ps). Open the elevated PowerShell console and allow to execute the unsigned scripts:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Next run the script: C:\PS\drv_cleanup.ps1

execution policy powershell

The script will remove unused drivers. After its completion, restart your computer and check if everything works properly and, if necessary, reinstall the appropriate driver.

In our case, after the execution of the script the size of a folder FileRepository reduced from 11 to 1.5 GB. Not bad!

You may also like:

Add Calendar Permissions in Office 365 via PowerSh... This is a tutorial on how to add calendar permissions in Office 365 for your users via PowerShell. You can add the permissions on a specific user’s ma...
Download Dell Drivers the Easy Way via FTP Site Whether you work at a Helpdesk or are an IT Administrator, a lot of our readers download drivers from the Dell website a lot. I know I am personally d...
How to Get List of Installed Programs in Windows 1... In this simple guide, we will show you two different ways of how to get a list of installed programs in Windows 10, 8 or Windows 7 using built-in comm...
Lenovo Yoga 13 Wifi Keeps Disconnecting Lenovo Yoga We have been dealing with some Lenovo Yoga 13 ultrabooks recently and the wireless cards keep disconnecting and then refuse to reconnect....
How to copy files with BITS using PowerShell? If you use local (and global) networks, you might know that files between systems are transferring by using SMB, FTP or HTTP protocols. The problem wi...
  1. Posted by Saed Zakari
  2. Posted by Tixx
  3. Posted by Vasy

Add Your Comment