An aggregate view of all SPDisposeCheck results as one single CSV file (PowerShell)

After you used the Run SPDisposeCheck on all assemblies in a specific directory with PowerShell script to validate all the assemblies in those packages. A report is created for each assembly found.

In order to visualize the results and communicate them towards the SharePoint team, you could use the following script that will open each SPDispose log file and combine them into 1 CSV file.

You can use Excel to open this csv file and create the pivot tables and diagrams you need in there.

cls
Write-Host "********************************************************************************************************************"
Write-Host "| This script will collect all the SPDisposeCheck result files and create one csv file with them for reporting	   |"
Write-Host "********************************************************************************************************************"
Write-Host

cls
$wspdir = Read-Host "Provide directory where all the result files are located"

#Retrieve the wsp files in this folder
$fileEntries = [IO.Directory]::GetFiles($wspdir,"*.txt");

$counter = 0;
$coll = @();

foreach($fileName in $fileEntries) 
{ 
	$content = Get-Content $fileName;
	$obj = new-object PSObject
	
	foreach($line in $content){
		#check if this line starts with ID: SPDisposeCheckID_
		if($line.StartsWith("ID: SPDisposeCheckID_")){
			$ID = $line.Replace("ID: SPDisposeCheckID_","");
			
			if($ID -eq 140){
				continue #false positive
			}
			
			$obj = new-object PSObject
			$obj | add-member -membertype NoteProperty  -name "Path" -value $fileName
			$obj | add-member -membertype NoteProperty  -name "SPDisposeCheckID" -value $ID -Force

			$counter = 0;
			$coll += $obj;
		}
		
		#Method information
		if($counter -eq 2){
			$line = $line.Remove(0,8) #remove Method: from string
			$obj | add-member -membertype NoteProperty  -name "Method" -value $line -Force
		}
		
		#Statement information
		if($counter -eq 3){
			$line = $line.Remove(0,11) #remove Statement: from string
			$obj | add-member -membertype NoteProperty  -name "Statement" -value $line -Force
		}
		
		#Notes information
		if($counter -eq 4){
			$line = $line.Remove(0,7) #remove Notes: from string
			$obj | add-member -membertype NoteProperty  -name "Notes" -value $line -Force
		}
		
		#More information
		if($counter -eq 4){
			$line = $line.Remove(0,18) #remove More information: from string
			$obj | add-member -membertype NoteProperty  -name "More information" -value $line -Force
		}
		
		$counter++
	}
	
	$coll | export-csv -Delimiter ';' "$wspdir\spdisposecheckrapport.csv" -notypeinformation
} 

The csv file named spdisposecheckrapport.csv will be stored in the same location as the result files are located.

Hope it helps!

/T

VN:F [1.9.22_1171]
Rating: 7.8/10 (4 votes cast)
VN:F [1.9.22_1171]
Rating: +3 (from 3 votes)

Unpack WSP packages in a given directory by 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 extract the content of the WSP files by PowerShell, we need to use a built-in tool (extrac32.exe) that is available in your system32 directory.

The following script will un-pack all the WSP packages into their own directory.

cls
Write-Host "**************************************************************************************************"
Write-Host "| This script will unpack the WSP packages that it finds in a provided directory |"
Write-Host "**************************************************************************************************"
Write-Host

cls
$wspdir = Read-Host "Provide directory where all the wsp's are located"
$exportdir = "$wspdir\Export-$((get-date).toString('yyyyMMdd-hhmmss'))\"

#Retrieve the wsp files in this folder and subfolders
$s = [system.IO.SearchOption]::AllDirectories
$fileEntries = [IO.Directory]::GetFiles($wspdir,"*.wsp",$s); 
foreach($fullFileName in $fileEntries) 
{ 
	$fileName = $(Get-Item $fullFileName).Name;
 	$dirName =  $fileName.Replace(".wsp","");
	$path = $exportdir + $dirName;
 	$dir = [IO.Directory]::CreateDirectory($path) 

	#uncab
	Write-Host "Export $fileName started" -ForegroundColor Yellow
	$destination = $path
	C:\Windows\System32\extrac32.exe $fullFileName /e /Y /L $destination
}

Once this operation is done you can use the following script to validate the assemblies: http://tomvangaever.be/blogv2/2012/06/run-spdisposecheck-on-all-assemblies-in-a-specific-directory-with-powershell/
Hope it helps!

VN:F [1.9.22_1171]
Rating: 9.6/10 (7 votes cast)
VN:F [1.9.22_1171]
Rating: +6 (from 6 votes)