You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to reduce the number of hard to debug errors, we run our PowerShell scripts with Set-StrictMode -Version Latest. This lets us catch issues where we e.g. have misspelled a variable name (or forgot to assign it before using it) during runtime. But it would be immensely useful to catch these kinds of errors before we run the scripts, e.g. during an automated build.
We have deployment scripts that run for quite a long time (several hours), and silly misspelled variable names or misplaced variable assignments then costs quite a bit of development time. Catching these errors early would be immensely useful.
Example of something that should cause an error:
function Get-Foobar()
{
if ($b + 2 -gt 5)
{
return $b
}
return 5
}
This would be OK:
function Get-Foobar($b)
{
if ($b + 2 -gt 5)
{
return $b
}
return 5
}
As would this:
function Get-Foobar()
{
$b = 123;
if ($b + 2 -gt 5)
{
return $b
}
return 5
}
The text was updated successfully, but these errors were encountered:
I agree, this rule would have saved me a lot of time in long-running scripts that cannot be easily reentered. I expect that someone will say "just make sure you spell your variables correctly!" and obviously that defeats the point of the analyzer.
Bumping this suggestion, hope it becomes a feature.
In order to reduce the number of hard to debug errors, we run our PowerShell scripts with Set-StrictMode -Version Latest. This lets us catch issues where we e.g. have misspelled a variable name (or forgot to assign it before using it) during runtime. But it would be immensely useful to catch these kinds of errors before we run the scripts, e.g. during an automated build.
We have deployment scripts that run for quite a long time (several hours), and silly misspelled variable names or misplaced variable assignments then costs quite a bit of development time. Catching these errors early would be immensely useful.
Example of something that should cause an error:
This would be OK:
As would this:
The text was updated successfully, but these errors were encountered: