How to: Run SPCAF via PowerShell

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

File Description
SPCAF.PowerShell.dll SPCAF Self Contained PowerShell Module
AnalyzeSolutionsLocally.ps1 Sample PowerShell script which analyzes a given set of WSPs 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

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 (SPCAF.PowerShell.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. Support 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 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 level for log messages. Valid values are: quiet, minimal, normal, Default
TempDirectory String No Optional path to the temp folder.
SkipProjectCreation Boolean No Optional Boolean. Default FALSE. If TRUE no project (.spcaf) file is created as an output of the analysis.
TimeOut Integer No Optional seconds after the analysis should be canceled automatically.

Code sample

 Import-Module "x:\spcaf\SPCAF.PowerShell.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
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.