Expand Minimize

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.

CheckId SPC059103
TypeName DoNotWriteCodeInGlobalScope
Severity Warning
Type PowerShell File

Bad Practice

$foo = 1;
Good Practice
function foobar($foo) {
  #...
}
foo(1);

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.