@@ -130,10 +130,12 @@ private void FindPSScriptAnalyzer()
130
130
using ( var ps = System . Management . Automation . PowerShell . Create ( ) )
131
131
{
132
132
ps . Runspace = this . analysisRunspace ;
133
+
133
134
var modules = ps . AddCommand ( "Get-Module" )
134
135
. AddParameter ( "List" )
135
136
. AddParameter ( "Name" , "PSScriptAnalyzer" )
136
137
. Invoke ( ) ;
138
+
137
139
var psModule = modules == null ? null : modules . FirstOrDefault ( ) ;
138
140
if ( psModule != null )
139
141
{
@@ -160,10 +162,12 @@ private void ImportPSScriptAnalyzer()
160
162
using ( var ps = System . Management . Automation . PowerShell . Create ( ) )
161
163
{
162
164
ps . Runspace = this . analysisRunspace ;
163
- var module = ps . AddCommand ( "Import-Module" ) .
164
- AddParameter ( "ModuleInfo" , scriptAnalyzerModuleInfo )
165
+
166
+ var module = ps . AddCommand ( "Import-Module" )
167
+ . AddParameter ( "ModuleInfo" , scriptAnalyzerModuleInfo )
165
168
. AddParameter ( "PassThru" )
166
169
. Invoke ( ) ;
170
+
167
171
if ( module == null )
168
172
{
169
173
this . scriptAnalyzerModuleInfo = null ;
@@ -186,13 +190,16 @@ private void EnumeratePSScriptAnalyzerRules()
186
190
using ( var ps = System . Management . Automation . PowerShell . Create ( ) )
187
191
{
188
192
ps . Runspace = this . analysisRunspace ;
193
+
189
194
var rules = ps . AddCommand ( "Get-ScriptAnalyzerRule" ) . Invoke ( ) ;
190
195
var sb = new StringBuilder ( ) ;
191
196
sb . AppendLine ( "Available PSScriptAnalyzer Rules:" ) ;
197
+
192
198
foreach ( var rule in rules )
193
199
{
194
200
sb . AppendLine ( ( string ) rule . Members [ "RuleName" ] . Value ) ;
195
201
}
202
+
196
203
Logger . Write ( LogLevel . Verbose , sb . ToString ( ) ) ;
197
204
}
198
205
}
@@ -209,6 +216,7 @@ private void InitializePSScriptAnalyzer()
209
216
private IEnumerable < PSObject > GetDiagnosticRecords ( ScriptFile file )
210
217
{
211
218
IEnumerable < PSObject > diagnosticRecords = Enumerable . Empty < PSObject > ( ) ;
219
+
212
220
if ( this . scriptAnalyzerModuleInfo != null )
213
221
{
214
222
using ( var ps = System . Management . Automation . PowerShell . Create ( ) )
@@ -218,15 +226,17 @@ private IEnumerable<PSObject> GetDiagnosticRecords(ScriptFile file)
218
226
LogLevel . Verbose ,
219
227
String . Format ( "Running PSScriptAnalyzer against {0}" , file . FilePath ) ) ;
220
228
221
- // currently not working with include rules
222
229
diagnosticRecords = ps . AddCommand ( "Invoke-ScriptAnalyzer" )
223
230
. AddParameter ( "ScriptDefinition" , file . Contents )
231
+ . AddParameter ( "IncludeRule" , IncludedRules )
224
232
. Invoke ( ) ;
225
233
}
226
234
}
235
+
227
236
Logger . Write (
228
237
LogLevel . Verbose ,
229
238
String . Format ( "Found {0} violations" , diagnosticRecords . Count ( ) ) ) ;
239
+
230
240
return diagnosticRecords ;
231
241
}
232
242
0 commit comments