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
{{ message }}
Repository navigation
Rule request: Avoid reserved words for functions names #2099
According the document about Reserved Words, the reserved words that cannot be used as identifiers because they
have a special meaning in PowerShell:
about_Reserved_Words
Short description
Lists the reserved words that cannot be used as identifiers because they
have a special meaning in PowerShell.
Long description
There are certain words that have special meaning in PowerShell. When these
words appear without quotation marks, PowerShell attempts to apply their
special meaning rather than treating them as character strings. To use these
words as parameter arguments in a command or script without invoking their
special meaning, enclose the reserved words in quotation marks.
The following are the reserved words in PowerShell:
assembly exit process
base filter public
begin finally return
break for sequence
catch foreach static
class from (*) switch
command function throw
configuration hidden trap
continue if try
data in type
define (*) inlinescript until
do interface using
dynamicparam module var (*)
else namespace while
elseif parallel workflow
end param
enum private
(*) These keywords are reserved for future use.
It would be nice if the script analyzer warns (or even errors) if any of these names are used for a function name.
E.g. I would expect the following script definition to return an issue:
Invoke-ScriptAnalyzer-ScriptDefinition {function if {}}.ToString()
Thanks for flagging this. I did not know this was possible!
I've written a new rule AvoidReservedWordsAsFunctionNames to address this - I also wrote a blog post about putting it together - if that's of any interest!
I also wrote a blog post about putting it together - if that's of any interest!
Fyi: I have created my first AvoidUsingArrayList rule -actually, my first C# GitHub contribution ever- based on your helpful block post.
Two minor things popped up while doing so:
"Firstly, we update the number of tests in that test file to 71; nice and simple!"
This appears already outdated due to:
I have little knowledge of C#, My programming knowledge is mainly based on other languages (as PowerShell and .Net), therefore I had some trouble to understand should be done at: "Building now will succeed, but running the tests shows some other issues:"
The answer is actually in the PSScriptAnalyzer readme (where I assumed script analyzer usage guidelines and didn't expect to also find build/test instructions). In other words, a small referral/link in your blog to this might help for PowerShell authors that have little C#(/builder) knowledge.
Anyways, thank you very much for your helpful guidance!
Activity
liamjpeters commentedon Sep 1, 2025
👋 iRon7,
Thanks for flagging this. I did not know this was possible!
I've written a new rule
AvoidReservedWordsAsFunctionNamesto address this - I also wrote a blog post about putting it together - if that's of any interest!iRon7 commentedon Apr 15, 2026
Liam Peters (@liamjpeters)
Fyi: I have created my first
AvoidUsingArrayListrule -actually, my firstC#GitHub contribution ever- based on your helpful block post.Two minor things popped up while doing so:
This appears already outdated due to:
C#, My programming knowledge is mainly based on other languages (as PowerShell and .Net), therefore I had some trouble to understand should be done at: "Building now will succeed, but running the tests shows some other issues:"The answer is actually in the PSScriptAnalyzer readme (where I assumed script analyzer usage guidelines and didn't expect to also find build/test instructions). In other words, a small referral/link in your blog to this might help for PowerShell authors that have little
C#(/builder) knowledge.Anyways, thank you very much for your helpful guidance!