@@ -52,15 +52,15 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
5252 requiresTransformationAttribute = true ;
5353 }
5454
55+ // do not run the rule if the script requires PS version 5
56+ // but PSSA in invoked through PS version < 5
5557 if ( sbAst != null
56- && sbAst . ScriptRequirements != null
57- && sbAst . ScriptRequirements . RequiredPSVersion != null
58- && sbAst . ScriptRequirements . RequiredPSVersion . Major == 5 )
58+ && sbAst . ScriptRequirements != null
59+ && sbAst . ScriptRequirements . RequiredPSVersion != null
60+ && sbAst . ScriptRequirements . RequiredPSVersion . Major == 5
61+ && requiresTransformationAttribute )
5962 {
60- if ( requiresTransformationAttribute )
61- {
6263 yield break ;
63- }
6464 }
6565
6666 IEnumerable < Ast > funcDefAsts = ast . FindAll ( testAst => testAst is FunctionDefinitionAst , true ) ;
@@ -153,7 +153,12 @@ private bool WrongCredentialUsage(ParameterAst parameter, bool requiresTransform
153153 return false ;
154154 }
155155
156- var credentialAttribute = parameter . Attributes . FirstOrDefault ( paramAttribute => paramAttribute . TypeName . GetReflectionType ( ) == typeof ( CredentialAttribute ) ) ;
156+ var credentialAttribute = parameter . Attributes . FirstOrDefault (
157+ paramAttribute =>
158+ paramAttribute . TypeName . GetReflectionType ( ) == typeof ( CredentialAttribute )
159+ || paramAttribute . TypeName . FullName . Equals (
160+ "System.Management.Automation.Credential" ,
161+ StringComparison . OrdinalIgnoreCase ) ) ;
157162
158163 // check that both exists and pscredentialtype comes before credential attribute
159164 if ( psCredentialType != null
0 commit comments