Question [Tutoriel] Usage de PSScriptAnalyzer

Plus d'informations
il y a 7 ans 5 mois #22547 par Laurent Dardenne
Un tutoriel sur l'usage de PSScripAnalzer et la création de règle en Powershell.

Règles:
github.com/ChrisLGardner/ScriptAnalyzerRules

Message édité par: Laurent Dardenne, à: 20/07/19 11:12

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 6 ans 3 semaines #25099 par Laurent Dardenne
Un fichier ps1xml, déclarant les méthodes d'extension présentes dans la dll Microsoft.Windows.PowerShell.ScriptAnalyzer.dll :
[code:1]
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<Types>
<Type>
<Name>System.Management.Automation.Language.ParamBlockAst</Name>
<Members>
<ScriptMethod>
<Name>GetCmdletBindingAttributeAst</Name>
<Script> switch ($args.Count) {
# GetCmdletBindingAttributeAst([System.Management.Automation.Language.ParamBlockAst] $paramBlockAst)
0 { [Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions.Extensions]::GetCmdletBindingAttributeAst($this) }

default { throw \"No overload for 'GetCmdletBindingAttributeAst' takes the specified number of parameters.\" }
}
</Script>
</ScriptMethod>
</Members>
</Type>
<Type>
<Name>System.Management.Automation.Language.AttributeAst</Name>
<Members>
<ScriptMethod>
<Name>IsCmdletBindingAttributeAst</Name>
<Script> switch ($args.Count) {
# IsCmdletBindingAttributeAst([System.Management.Automation.Language.AttributeAst] $attributeAst)
0 { [Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions.Extensions]::IsCmdletBindingAttributeAst($this) }

default { throw \"No overload for 'IsCmdletBindingAttributeAst' takes the specified number of parameters.\" }
}
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>GetSupportsShouldProcessAst</Name>
<Script> switch ($args.Count) {
# GetSupportsShouldProcessAst([System.Management.Automation.Language.AttributeAst] $attributeAst)
0 { [Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions.Extensions]::GetSupportsShouldProcessAst($this) }

default { throw \"No overload for 'GetSupportsShouldProcessAst' takes the specified number of parameters.\" }
}
</Script>
</ScriptMethod>
</Members>
</Type>
<Type>
<Name>System.Management.Automation.Language.NamedAttributeArgumentAst</Name>
<Members>
<ScriptMethod>
<Name>GetValue</Name>
<Script> switch ($args.Count) {
# GetValue([System.Management.Automation.Language.NamedAttributeArgumentAst] $attrAst)
0 { [Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions.Extensions]::GetValue($this) }

# GetValue([System.Management.Automation.Language.NamedAttributeArgumentAst] $attrAst, [ref] [System.Management.Automation.Language.ExpressionAst] $argumentAst)
1 { [Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions.Extensions]::GetValue($this,$args[0]) }

default { throw \"No overload for 'GetValue' takes the specified number of parameters.\" }
}
</Script>
</ScriptMethod>
</Members>
</Type>
<Type>
<Name>System.Management.Automation.Language.FunctionDefinitionAst</Name>
<Members>
<ScriptMethod>
<Name>GetParameterAsts</Name>
<Script> switch ($args.Count) {
# GetParameterAsts([System.Management.Automation.Language.FunctionDefinitionAst] $functionDefinitionAst)
0 { [Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions.Extensions]::GetParameterAsts($this) }

# GetParameterAsts([System.Management.Automation.Language.FunctionDefinitionAst] $functionDefinitionAst, [ref] [System.Management.Automation.Language.ParamBlockAst] $paramBlockAst)
1 { [Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions.Extensions]::GetParameterAsts($this,$args[0]) }

default { throw \"No overload for 'GetParameterAsts' takes the specified number of parameters.\" }
}
</Script>
</ScriptMethod>
</Members>
</Type>
<Type>
<Name>System.String</Name>
<Members>
<ScriptMethod>
<Name>GetLines</Name>
<Script> switch ($args.Count) {
# GetLines([string] $text)
0 { [Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions.Extensions]::GetLines($this) }

default { throw \"No overload for 'GetLines' takes the specified number of parameters.\" }
}
</Script>
</ScriptMethod>
</Members>
</Type>
</Types>

[/code:1]<br><br>Message édité par: Laurent Dardenne, à: 7/03/18 18:35

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 5 ans 11 mois #25241 par Laurent Dardenne
On peut désormais utiliser un fichier de configuration pour les règles externe (script module).

Cela fonctionne également avec VSCode .

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.067 secondes
Propulsé par Kunena