Best Practice |
Rules to warn if common best practices are not used.
Index
Rule | Description | Type | Severity |
---|---|---|---|
SPC059101: Avoid usage of $ErrorActionPreference | Using $ErrorActionPreference can create some strange behavior by purposfuly disabling errors from happening. Potential errors should be checked for with an if statement before they can happen, or be caught in a try-catch-finally. | PowerShell File | CriticalWarning |
SPC059102: Do not use Write-Host | Write-Host is never needed in PowerShell CmdLets. Instead use the correct Write-<verb> for your situation. Write-Error for Errors, Write-Debug for debug, Write-Verbose for extra informaiton on request. | PowerShell File | Information |
SPC059103: Do not write code in the global scope | Assignment to variables and usage of variables, in the global scope can cause value conflicts across scripts. It is recommended to use methods and local variables where possible. | PowerShell File | Warning |
SPC059104: Avoid using Backticks (`) to spread code over multiple lines | Backticks are used to spread lines of code in PowerShell over multiple lines. The downside is that they are difficult to see and hard to maintain and grasp a clear intent for the code structure. | PowerShell File | Warning |
SPC059105: Use [CmdletBinding()] with Write Verbose/Debug | CmdletBinding allows usage of -Verbose and -Debug switches to apply to the contents of methods in the PowerShell Script and should be applied where Write-Verbose or Write-Debug CmdLets are used. | PowerShell File | Warning |
SPC059106: Do not use CmdLet Aliases | Do not use CmdLet aliases with the exceptions of "cat", "cp", "curl", "diff", "echo", "kill", "ls", "man", "mount", "mv", "ps", "pwd", "rm", "sleep", "tee", "type", "wget" which are acceptable and whitelisted. | PowerShell File | Error |
SPC059107: Do not default true switch parameter | Using a default value of true on a switch property will have undesired results. | PowerShell File | CriticalError |
SPC059108: Exported CmdLets should include comment help | Comments should be provided which supple the help context of the Exported CmdLet for use with Get-Help. | PowerShell File | Information |
SPC059109: Provide verbose messaging for the end user | Verbose messaging can allow indepth program flow when required to the end user, allowing CmdLets to be more easily used especially in cases where an error occurs. | PowerShell File | Information |
Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.