mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-16 16:24:03 +00:00
New "Analyze-This" example
This commit is contained in:
@@ -1,24 +1,50 @@
|
|||||||
$xlfilename = $pwd.path -replace "^.*\\(.*?)\\(.*?)$", '$1-$2.xlsx'
|
<#
|
||||||
$xlpath = Join-Path -Path $env:TEMP -ChildPath $xlfilename
|
.Synopsis
|
||||||
Remove-Item -Path $xlpath -ErrorAction SilentlyContinue
|
|
||||||
|
|
||||||
$ScriptAnalyzerResults = Invoke-ScriptAnalyzer .
|
#>
|
||||||
|
[CmdletBinding()]
|
||||||
|
param (
|
||||||
|
[parameter(ValueFromPipeline = $true)]
|
||||||
|
$Path = $PWD,
|
||||||
|
$xlfile = "$env:TEMP\ScriptAnalyzer.xlsx",
|
||||||
|
$ChartType = 'BarClustered' ,
|
||||||
|
[switch]$Quiet
|
||||||
|
)
|
||||||
|
|
||||||
$xlPkg = $ScriptAnalyzerResults | Group-Object -Property RuleName -NoElement | Sort-Object -Property Name |
|
begin {
|
||||||
Select-Object -Property Name,Count |
|
Remove-Item -Path $xlfile -ErrorAction SilentlyContinue
|
||||||
Export-Excel -Path $xlpath -WorksheetName Summary -AutoSize -PassThru
|
$xlparams = @{
|
||||||
|
Path = $xlfile
|
||||||
$params = @{
|
|
||||||
WorksheetName = 'FullResults'
|
WorksheetName = 'FullResults'
|
||||||
AutoSize = $true
|
AutoSize = $true
|
||||||
AutoFilter = $true
|
AutoFilter = $true
|
||||||
IncludePivotTable = $true
|
|
||||||
Activate = $true
|
Activate = $true
|
||||||
PivotRows = 'Severity', 'RuleName'
|
Show = (-not $Quiet)
|
||||||
|
}
|
||||||
|
$pivotParams = @{
|
||||||
|
PivotTableName = 'BreakDown'
|
||||||
PivotData = @{RuleName = 'Count' }
|
PivotData = @{RuleName = 'Count' }
|
||||||
IncludePivotChart = $true
|
PivotRows = 'Severity', 'RuleName'
|
||||||
ChartType = 'BarClustered'
|
PivotColumns = 'Location'
|
||||||
Show = $true
|
PivotTotals = 'Rows'
|
||||||
|
}
|
||||||
|
$dirsToProcess = @()
|
||||||
|
}
|
||||||
|
process {
|
||||||
|
if ($path.fullName) {$dirsToProcess += $path.fullName}
|
||||||
|
elseif ($path.path) {$dirsToProcess += $path.Path}
|
||||||
|
else {$dirsToProcess += $path}
|
||||||
}
|
}
|
||||||
|
|
||||||
Export-Excel -ExcelPackage $xlpkg -InputObject $ScriptAnalyzerResults @params
|
end {
|
||||||
|
$pivotParams['-PivotChartDefinition'] = New-ExcelChartDefinition -ChartType $chartType -Column $dirsToProcess.Count -Title "Script analysis" -LegendBold
|
||||||
|
$xlparams['PivotTableDefinition'] = New-PivotTableDefinition @pivotParams
|
||||||
|
|
||||||
|
$dirsToProcess | ForEach-Object {
|
||||||
|
$dirName = (Resolve-Path -Path $_) -replace "^.*\\(.*?)\\(.*?)$", '$1-$2'
|
||||||
|
Write-Progress -Activity "Running Script Analyzer" -CurrentOperation $dirName
|
||||||
|
Invoke-ScriptAnalyzer -Path $_ -ErrorAction SilentlyContinue |
|
||||||
|
Add-Member -MemberType NoteProperty -Name Location -Value $dirName -PassThru
|
||||||
|
} | Export-Excel @xlparams
|
||||||
|
Write-Progress -Activity "Running Script Analyzer" -Completed
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user