The "C:\Windows\Installer" can often grow very large in size due to applications such as Microsoft Office being regularly patched. Superseded patches get left behind leaving them in an orphaned state. The MSIPatches module can detect and move the orphaned patches freeing up valuable disk space. This module requires the MSI module by Heath Stewart. Installation instructions are in the next section
MSIPactches functions Get-MsiPatch.ps1
- Lists all msp files in
$env:SystemRoot\Installer\
- Calculates their total size
- Gets installed patches and size
- Gets orphaned patches and size
Get-OrphanedPatch.ps1
- Lists all orphaned patches in
$env:SystemRoot\Installer\
- Outputs the objects as
[System.IO.FileInfo]
which can be piped to the next functions.
Move-OrphanedPatch.ps1
- Moves all orphaned patches in
$env:SystemRoot\Installer\
to a specified location.
Restore-OrphanedPatch.ps1
- Restores all previously backed up orphaned patches to
$env:SystemRoot\Installer\
You can now install this module from the PowerShell gallery
Install-Module MSIPatches
Or you can install it manually
# Install the MSI package
Install-Package msi -Provider PowerShellGet
# Download and unzip the MSIPatches module.
# Unblock the files. E.g:
Get-ChildItem C:\MSIPatches\ -Recurse | Unblock-File
# Import the module
Import-Module C:\MSIPatches\MSIPatches.psd1 -Force -Verbose
# List the commands in the MSIPatches module
Get-Command -Module MSIPatches
CommandType Name Version Source
----------- ---- ------- ------
Function Get-MsiPatch 1.0.21 MSIPatches
Function Get-OrphanedPatch 1.0.21 MSIPatches
Function Move-OrphanedPatch 1.0.21 MSIPatches
Function Restore-OrphanedPatch 1.0.21 MSIPatches
# Get-Help
Get-Help about_MSIPatches
Get-Help Get-MsiPatches
# Get a count of all MSI patches with Get-MsiPatch
Get-MsiPatch
# Get-OrphanedPatch returns basic information. [System.IO.FileInfo] objects.
Get-OrphanedPatch
# Pass the [System.IO.FileInfo] objects through the pipeline to Move-OrphanedPatch
Get-OrphanedPatch | Move-OrphanedPatch -Destination C:\Backup
# 'y' to create the directory if it doesn't exist.
# After you move the orphaned patches you can run the Get-MsiPatch command again and see the results.
# Restore previously backed up msp files using the Restore-OrphanedPatch command
Restore-OrphanedPatch -BackupLocation <String>
# If the directory doesn't exist/inaccessible or doesn't contain any msp files, the following will display
# Note: you can pass the [System.IO.FileInfo] objects through the pipeline to Remove-Item to permanenlty
#delete the msp files. Recommend you pipe to Move-OrphanedPatch instead.
Get-OrphanedPatch | Remove-Item