Skip to content

Commit 0b8e8a2

Browse files
author
Kapil Borle
committed
Add a method to enumerate PSScriptAnalyzer cmdlets
1 parent 44ca6b3 commit 0b8e8a2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/PowerShellEditorServices/Analysis/AnalysisService.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public AnalysisService(string settingsPath, ILogger logger)
129129
this.analysisRunspacePool.Open();
130130

131131
ActiveRules = IncludedRules.ToArray();
132+
EnumeratePSScriptAnalyzerCmdlets();
132133
EnumeratePSScriptAnalyzerRules();
133134
}
134135
catch (Exception e)
@@ -346,6 +347,29 @@ private static PSModuleInfo FindPSScriptAnalyzerModule(ILogger logger)
346347
}
347348
}
348349

350+
private void EnumeratePSScriptAnalyzerCmdlets()
351+
{
352+
if (hasScriptAnalyzerModule)
353+
{
354+
var sb = new StringBuilder();
355+
var commands = InvokePowerShell(
356+
"Get-Command",
357+
new Dictionary<string, object>
358+
{
359+
{"Module", "PSScriptAnalyzer"}
360+
});
361+
362+
var commandNames = commands?
363+
.Select(c => c.ImmediateBaseObject as CmdletInfo)
364+
.Where(c => c != null)
365+
.Select(c => c.Name) ?? Enumerable.Empty<string>();
366+
367+
sb.AppendLine("The following cmdlets are available in the imported PSScriptAnalyzer module:");
368+
sb.AppendLine(String.Join(Environment.NewLine, commandNames.Select(s => " " + s)));
369+
this.logger.Write(LogLevel.Verbose, sb.ToString());
370+
}
371+
}
372+
349373
private void EnumeratePSScriptAnalyzerRules()
350374
{
351375
if (hasScriptAnalyzerModule)

0 commit comments

Comments
 (0)