Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Severity Level: Warning
Default state: Always enabled
Description
This rule detects the use of the sequences > and >= in conditional statements where comparison
operators are intended. This rule catches instances where > or >= appears inside if, elseif,
while, and do-while statements, which are almost always unintentional.
In many programming languages, > is the comparison operator for greater than, but PowerShell
uses -gt (greater than) and -ge (greater or equal) instead. It's easy to accidentally use the
wrong operator, especially if you're familiar with other languages.
Example
Noncompliant
if ($a > $b)
{
...
}
Compliant
if ($a -gt $b)
{
...
}
Configure rule
This rule is always enabled and isn't configurable. Use one of the following methods to avoid using this rule:
- Create a custom rule configuration file to include only the rules you want or exclude the rules you don't want.
- Add the appropriate rule suppression attributes to your code to suppress the rule for specific code blocks. For more information, see the Suppressing rules section of Using PSScriptAnalyzer.