Skip to content

Detect and move orphaned patches from "C:\Windows\Installer" using this PowerShell module

Notifications You must be signed in to change notification settings

markkerry/MSIPatches

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MSIPatches

Build status PowerShell Gallery - MSIPatches License Minimum Supported PowerShell Version

About

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\

Installation

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

Examples

# Get a count of all MSI patches with Get-MsiPatch
Get-MsiPatch

Get-MsiPatch

# Get-OrphanedPatch returns basic information. [System.IO.FileInfo] objects.
Get-OrphanedPatch

Get-OrphanedPatch

# Pass the [System.IO.FileInfo] objects through the pipeline to Move-OrphanedPatch
Get-OrphanedPatch | Move-OrphanedPatch -Destination C:\Backup

Move-OrphanedPatch

# 'y' to create the directory if it doesn't exist.

Move-OrphanedPatch

# After you move the orphaned patches you can run the Get-MsiPatch command again and see the results.

Move-OrphanedPatch

# Restore previously backed up msp files using the Restore-OrphanedPatch command
 Restore-OrphanedPatch -BackupLocation <String>

Restore-OrphanedPatch

# If the directory doesn't exist/inaccessible or doesn't contain any msp files, the following will display

Restore-OrphanedPatch
Restore-OrphanedPatch

# 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

About

Detect and move orphaned patches from "C:\Windows\Installer" using this PowerShell module

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published