Skip to content

Commit 6dcd845

Browse files
Merge pull request #364 from MicrosoftDocs/main
Auto Publish – main to live - 2025-12-03 23:03 UTC
2 parents edd1fec + 9ade24c commit 6dcd845

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
description: Avoid reserved words as function names
3+
ms.date: 08/31/2025
4+
ms.topic: reference
5+
title: AvoidReservedWordsAsFunctionNames
6+
---
7+
# AvoidReservedWordsAsFunctionNames
8+
9+
**Severity Level: Warning**
10+
11+
## Description
12+
13+
Avoid using reserved words as function names. Using reserved words as function names can cause
14+
errors or unexpected behavior in scripts.
15+
16+
## How to Fix
17+
18+
Avoid using any of the reserved words as function names. Choose a different name that's not a
19+
reserved word.
20+
21+
See [about_Reserved_Words][01] for a list of reserved words in PowerShell.
22+
23+
## Example
24+
25+
### Wrong
26+
27+
```powershell
28+
# Function is a reserved word
29+
function function {
30+
Write-Host "Hello, World!"
31+
}
32+
```
33+
34+
### Correct
35+
36+
```powershell
37+
# myFunction is not a reserved word
38+
function myFunction {
39+
Write-Host "Hello, World!"
40+
}
41+
```
42+
43+
<!-- link references -->
44+
[01]: /powershell/module/microsoft.powershell.core/about/about_reserved_words

reference/docs-conceptual/PSScriptAnalyzer/Rules/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The PSScriptAnalyzer contains the following rule definitions.
2323
| [AvoidMultipleTypeAttributes<sup>1</sup>](./AvoidMultipleTypeAttributes.md) | Warning | Yes | |
2424
| [AvoidNullOrEmptyHelpMessageAttribute](./AvoidNullOrEmptyHelpMessageAttribute.md) | Warning | Yes | |
2525
| [AvoidOverwritingBuiltInCmdlets](./AvoidOverwritingBuiltInCmdlets.md) | Warning | Yes | Yes |
26+
| [AvoidReservedWordsAsFunctionNames](./AvoidReservedWordsAsFunctionNames.md) | Warning | Yes | |
2627
| [AvoidSemicolonsAsLineTerminators](./AvoidSemicolonsAsLineTerminators.md) | Warning | No | |
2728
| [AvoidShouldContinueWithoutForce](./AvoidShouldContinueWithoutForce.md) | Warning | Yes | |
2829
| [AvoidTrailingWhitespace](./AvoidTrailingWhitespace.md) | Warning | Yes | |

reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCorrectCasing.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ title: UseCorrectCasing
1111
## Description
1212

1313
This is a style/formatting rule. PowerShell is case insensitive wherever possible, so the casing of
14-
cmdlet names, parameters, keywords and operators does not matter. This rule nonetheless ensures
14+
cmdlet names, parameters, keywords and operators doesn't matter. This rule nonetheless ensures
1515
consistent casing for clarity and readability. Using lowercase keywords helps distinguish them from
1616
commands. Using lowercase operators helps distinguish them from parameters.
1717

@@ -34,31 +34,31 @@ Rules = @{
3434
}
3535
```
3636

37-
### Parameters
37+
## Parameters
3838

39-
#### Enable: bool (Default value is `$false`)
39+
### Enable: bool (Default value is `$false`)
4040

4141
Enable or disable the rule during ScriptAnalyzer invocation.
4242

43-
#### CheckCommands: bool (Default value is `$true`)
43+
### CheckCommands: bool (Default value is `$true`)
4444

45-
If true, require the case of all operators to be lowercase.
45+
If true, require the case of all command and parameter names to match their canonical casing.
4646

47-
#### CheckKeyword: bool (Default value is `$true`)
47+
### CheckKeyword: bool (Default value is `$true`)
4848

4949
If true, require the case of all keywords to be lowercase.
5050

51-
#### CheckOperator: bool (Default value is `$true`)
51+
### CheckOperator: bool (Default value is `$true`)
5252

53-
If true, require the case of all commands to match their actual casing.
53+
If true, require the case of all operators to be lowercase. For example: `-eq`, `-ne`, `-gt`
5454

5555
## Examples
5656

5757
### Wrong way
5858

5959
```powershell
6060
ForEach ($file in Get-childitem -Recurse) {
61-
$file.Extension -eq '.txt'
61+
$file.Extension -EQ '.txt'
6262
}
6363
6464
invoke-command { 'foo' } -runasadministrator

0 commit comments

Comments
 (0)