diff --git a/Engine/Helper.cs b/Engine/Helper.cs
index 24c5a12c2..a3009a7ef 100644
--- a/Engine/Helper.cs
+++ b/Engine/Helper.cs
@@ -605,18 +605,26 @@ public bool HasSplattedVariable(CommandAst cmdAst)
}
///
- /// Given a commandast, checks if the command is a Cmdlet.
+ /// Given a commandast, checks if the command is a known cmdlet, function or ExternalScript.
///
///
///
- public bool IsCmdlet(CommandAst cmdAst) {
+ public bool IsKnownCmdletFunctionOrExternalScript(CommandAst cmdAst)
+ {
if (cmdAst == null)
{
return false;
}
var commandInfo = GetCommandInfo(cmdAst.GetCommandName());
- return (commandInfo != null && commandInfo.CommandType == System.Management.Automation.CommandTypes.Cmdlet);
+ if (commandInfo == null)
+ {
+ return false;
+ }
+
+ return commandInfo.CommandType == CommandTypes.Cmdlet ||
+ commandInfo.CommandType == CommandTypes.Alias ||
+ commandInfo.CommandType == CommandTypes.ExternalScript;
}
///
diff --git a/Rules/AvoidPositionalParameters.cs b/Rules/AvoidPositionalParameters.cs
index 0fa54845d..d1c552957 100644
--- a/Rules/AvoidPositionalParameters.cs
+++ b/Rules/AvoidPositionalParameters.cs
@@ -52,7 +52,7 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName)
// MSDN: CommandAst.GetCommandName Method
if (cmdAst.GetCommandName() == null) continue;
- if ((Helper.Instance.IsCmdlet(cmdAst) || declaredFunctionNames.Contains(cmdAst.GetCommandName())) &&
+ if ((Helper.Instance.IsKnownCmdletFunctionOrExternalScript(cmdAst) || declaredFunctionNames.Contains(cmdAst.GetCommandName())) &&
(Helper.Instance.PositionalParameterUsed(cmdAst, true)))
{
PipelineAst parent = cmdAst.Parent as PipelineAst;
diff --git a/Rules/UseCmdletCorrectly.cs b/Rules/UseCmdletCorrectly.cs
index 8138e6dec..5293eaea9 100644
--- a/Rules/UseCmdletCorrectly.cs
+++ b/Rules/UseCmdletCorrectly.cs
@@ -129,7 +129,7 @@ private bool MandatoryParameterExists(CommandAst cmdAst)
return true;
}
- if (mandParams.Count == 0 || (Helper.Instance.IsCmdlet(cmdAst) && Helper.Instance.PositionalParameterUsed(cmdAst)))
+ if (mandParams.Count == 0 || (Helper.Instance.IsKnownCmdletFunctionOrExternalScript(cmdAst) && Helper.Instance.PositionalParameterUsed(cmdAst)))
{
returnValue = true;
}
diff --git a/Tests/Rules/AvoidPositionalParameters.tests.ps1 b/Tests/Rules/AvoidPositionalParameters.tests.ps1
index 1e0000a54..ebc11b144 100644
--- a/Tests/Rules/AvoidPositionalParameters.tests.ps1
+++ b/Tests/Rules/AvoidPositionalParameters.tests.ps1
@@ -15,6 +15,13 @@ Describe "AvoidPositionalParameters" {
$violations[0].Message | Should -Match $violationMessage
}
+ It "Triggers on alias" {
+ $violations = Invoke-ScriptAnalyzer -ScriptDefinition "gcm 'abc' 4 4.3"
+ $violations.Count | Should -Be 2
+ $violations.RuleName | Should -Contain $violationName
+ $violations.RuleName | Should -Contain 'PSAvoidUsingCmdletAliases'
+ }
+
}
Context "When there are no violations" {