Skip to content

Commit 90a3b5a

Browse files
committed
Add wild card support to Get-ScriptAnalyzerRule
1 parent 25a974b commit 90a3b5a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Engine/ScriptAnalyzer.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// THE SOFTWARE.
1111
//
1212

13+
using System.Text.RegularExpressions;
1314
using Microsoft.Windows.Powershell.ScriptAnalyzer.Commands;
1415
using Microsoft.Windows.Powershell.ScriptAnalyzer.Generic;
1516
using System;
@@ -192,8 +193,18 @@ public IEnumerable<IRule> GetRule(string[] moduleNames, string[] ruleNames)
192193

193194
if (ruleNames != null)
194195
{
195-
results = rules.Where<IRule>(item =>
196-
ruleNames.Contains(item.GetName(), StringComparer.OrdinalIgnoreCase));
196+
//Check wild card input for -Name parameter and create regex match patterns
197+
List<Regex> regexList = new List<Regex>();
198+
foreach (string ruleName in ruleNames)
199+
{
200+
Regex includeRegex = new Regex(String.Format("^{0}$", Regex.Escape(ruleName).Replace(@"\*", ".*")), RegexOptions.IgnoreCase);
201+
regexList.Add(includeRegex);
202+
}
203+
204+
results = from rule in rules
205+
from regex in regexList
206+
where regex.IsMatch(rule.GetName())
207+
select rule;
197208
}
198209
else
199210
{

0 commit comments

Comments
 (0)