Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
description: Avoid reserved words as function names
ms.date: 08/31/2025
ms.topic: reference
title: AvoidReservedWordsAsFunctionNames
---
# AvoidReservedWordsAsFunctionNames

**Severity Level: Warning**

## Description

Avoid using reserved words as function names. Using reserved words as function names can cause
errors or unexpected behavior in scripts.

## How to Fix

Avoid using any of the reserved words as function names. Choose a different name that's not a
reserved word.

See [about_Reserved_Words][01] for a list of reserved words in PowerShell.

## Example

### Wrong

```powershell
# Function is a reserved word
function function {
Write-Host "Hello, World!"
}
```

### Correct

```powershell
# myFunction is not a reserved word
function myFunction {
Write-Host "Hello, World!"
}
```

<!-- link references -->
[01]: /powershell/module/microsoft.powershell.core/about/about_reserved_words
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The PSScriptAnalyzer contains the following rule definitions.
| [AvoidMultipleTypeAttributes<sup>1</sup>](./AvoidMultipleTypeAttributes.md) | Warning | Yes | |
| [AvoidNullOrEmptyHelpMessageAttribute](./AvoidNullOrEmptyHelpMessageAttribute.md) | Warning | Yes | |
| [AvoidOverwritingBuiltInCmdlets](./AvoidOverwritingBuiltInCmdlets.md) | Warning | Yes | Yes |
| [AvoidReservedWordsAsFunctionNames](./AvoidReservedWordsAsFunctionNames.md) | Warning | Yes | |
| [AvoidSemicolonsAsLineTerminators](./AvoidSemicolonsAsLineTerminators.md) | Warning | No | |
| [AvoidShouldContinueWithoutForce](./AvoidShouldContinueWithoutForce.md) | Warning | Yes | |
| [AvoidTrailingWhitespace](./AvoidTrailingWhitespace.md) | Warning | Yes | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ title: UseCorrectCasing
## Description

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

Expand All @@ -34,31 +34,31 @@ Rules = @{
}
```

### Parameters
## Parameters

#### Enable: bool (Default value is `$false`)
### Enable: bool (Default value is `$false`)

Enable or disable the rule during ScriptAnalyzer invocation.

#### CheckCommands: bool (Default value is `$true`)
### CheckCommands: bool (Default value is `$true`)

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

#### CheckKeyword: bool (Default value is `$true`)
### CheckKeyword: bool (Default value is `$true`)

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

#### CheckOperator: bool (Default value is `$true`)
### CheckOperator: bool (Default value is `$true`)

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

## Examples

### Wrong way

```powershell
ForEach ($file in Get-childitem -Recurse) {
$file.Extension -eq '.txt'
$file.Extension -EQ '.txt'
}

invoke-command { 'foo' } -runasadministrator
Expand Down
Loading