How to: Run SPCAF via PowerShell

This article explains how to install and run SPCAF via PowerShell.

SPCAF is now available via PowerShell. Depending on your license the output will give you a full or trial report, either edit and use the supplied example script or create your own to suit your needs.

File Description
Rencore.Code.SPCAF.PowerShell.CmdLet.dll SPCAF Self Contained PowerShell Module
AnalyzeSolutionsLocally.ps1 Sample PowerShell script which analyzes a given set of WSP's locally with SPCAF (without SharePoint installed).
LoadAndAnalyzeSolutionsFromSharePoint.ps1 Sample PowerShell script which downloads all full trust solutions from the local SharePoint farm and analyzes them with SPCAF

Install SPCAF for PowerShell

In order to run SPCAF in PowerShell, you will need to go to our downloads page. Select "Integrations for Build and Deployment Processes" below the SPCAF section.

This will download Rencore.Code.SPCAF.Integrations.<version>.zip. Open the .zip and go to Integrations and PowerShell, extract the contents to the folder destination of your choice.

Run analysis from PowerShell

The SPCAF PowerShell Module can be run on any machine with support for .NET 4.0 and at least PowerShell v2.0. The supplied script also requires a SharePoint Farm to be deployed locally, however, it is easily modifiable to work remotely.

Run free analysis without SPCAF license

If you have no SPCAF license, SPCAF creates at least a summary report (format HTML) of the analysis which highlights the main issues and shows the code metrics in charts.

Run analysis with SPCAF license

If you have a valid SPCAF Quality Gate/SPCAF Farm Protection license copy the .lic file to the folder with the PowerShell cmdlet (Rencore.Code.SPCAF.PowerShell.CmdLet.dll) or provide the path the .lic file in the cmdlet argument "LicenseFiles".

Command Line Parameters

Parameter Value Mandatory Description
InputFiles String Array Yes List of input files or directory for the analysis. Supported formats: .wsp, .app, .dll, .exe, .zip
LicenseFiles String Array No Optional path to SPCAF license files. If no license file is given only the free feature are activated.
SettingsFile String No Optional name or path to the settings files (.spruleset) which defines the analyzers for the analysis.
Reports String Array No List of report formats which should be generated during the analysis. Possible values: .html, .pdf, . docx, .xml, .csv, dgml.
OutputFile String No Optional path of the output file. The reports will be written to the same location as the output file in the various formats.
Verbosity String No Optional level for verbosity to limit the detail levels for log messages. Valid values are: quiet|minimal|nomal|debug
  • Default: normal.
TempDirectory String No Optional path to the temp folder.
SkipPorjectCreation Boolean No Optional Boolean. If True no project (.spcaf) file is created as an output of the analysis.
  • Default: FALSE.
TimeOut Integer No Optional seconds after the analysis should be canceled automatically.

Code sample

 Import-Module "x:\spcaf\Rencore.Code.SPCAF.PowerShell.CmdLet.dll"

 $params = @{

    InputFiles = @("x:\spcaf")

    OutputFile = "x:\spcaf\SPCAF-Report.html"

    Reports = @("HTML")

    LicenseFiles = @("x:\spcaf\pro.lic")

    Timeout = 0 #Infinite timeout

    LogFile = "x:\spcaf\SPCAF.log"


 Invoke-SPCAFCodeAnalysis @params