Run SPDisposeCheck on all assemblies in a specific directory with PowerShell

How awesome would it be, If you could:

  1. Copy paste all the WSP’s that are installed in your farm into one directory
  2. Run a PowerShell script to unpack the content:
    http://tomvangaever.be/blogv2/2012/12/unpack-wsp-packages-in-a-given-directory-by-powershell/
  3. Have all the assemblies that are inside the WSP packages checked by SPDisposeCheck:
    http://tomvangaever.be/blogv2/2012/06/run-spdisposecheck-on-all-assemblies-in-a-specific-directory-with-powershell/
  4. Create one report by using this script to aggregate all results:
    http://tomvangaever.be/blogv2/2012/12/an-aggregate-view-of-all-spdisposecheck-results-files-as-csv-file-via-powershell/

In order to use this script, you need to have SPDisposeCheck installed on your machine, please download the free tool from here.

cls
Write-Host "**************************************************************************************************"
Write-Host "| This script will run the SPDisposeCheck tool on each dll that it finds in a provided directory |"
Write-Host "**************************************************************************************************"
Write-Host

$path = Read-Host "Directory path with the assemblies to check"

$Dir = get-childitem $path -recurse
$List = $Dir | where {$_.extension -eq ".dll"}

$export = $path+"\"+"SPDisposeCheck_$((get-date).toString('yyyyMMdd-hhmmss'))"
$dir = md $export

$List | ForEach-Object {
	Write-Host $_.name "is beeing checked..."
	$report = $export+"\"+$_.name+".spdisposecheck.txt"
	& "C:\Program Files (x86)\Microsoft\SharePoint Dispose Check\SPDisposeCheck.exe" $_.fullname | Out-File $report
}
Write-Host
Write-Host "The reports are stored in "$export
Write-Host
VN:F [1.9.20_1166]
Rating: 9.7/10 (3 votes cast)
VN:F [1.9.20_1166]
Rating: +3 (from 3 votes)
Run SPDisposeCheck on all assemblies in a specific directory with PowerShell, 9.7 out of 10 based on 3 ratings