-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fixes #12624 - Add more specific cases of sensitivity #12637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
michaeltlombardi
merged 6 commits into
MicrosoftDocs:main
from
sdwheeler:sdw-w543404-i12624-case-sensitivity
Jan 6, 2026
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c0c8099
Add more specific cases of sensitivity
sdwheeler 6832d2a
Apply suggestions from code review
sdwheeler 1328e24
Expand example
sdwheeler cc8cfa0
Merge branch 'main' into sdw-w543404-i12624-case-sensitivity
sdwheeler 906e28f
fix about_Split link
michaeltlombardi d57abf3
fix xref links
michaeltlombardi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
243 changes: 223 additions & 20 deletions
243
reference/5.1/Microsoft.PowerShell.Core/About/about_Case-Sensitivity.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,51 +1,254 @@ | ||
| --- | ||
| description: This article explains how PowerShell handles case-sensitivity. | ||
| Locale: en-US | ||
| ms.custom: wiki-migration | ||
| ms.date: 06/06/2022 | ||
| ms.date: 01/06/2026 | ||
| online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_case-sensitivity?view=powershell-5.1&WT.mc_id=ps-gethelp | ||
| title: about_Case-Sensitivity | ||
| --- | ||
| # about_Case-Sensitivity | ||
|
|
||
| ## Short description | ||
|
|
||
| PowerShell is as case-insensitive as possible while preserving case. | ||
| PowerShell is as case-insensitive while preserving case. | ||
|
|
||
| ## Long description | ||
|
|
||
| As a general principle, PowerShell is as case insensitive as possible while | ||
| As a general principle, PowerShell is case-insensitive wherever possible while | ||
| preserving case and not breaking the underlying OS. | ||
|
|
||
| ### On Unix-based systems | ||
| Windows-based systems are case-insensitive for most operations. However, | ||
| non-Windows systems are case-sensitive for most operations, especially for | ||
| file system and environment variable access. | ||
|
|
||
| On Unix-based systems, PowerShell is case-sensitive because filesystem | ||
| manipulation and environment variables directly affect the underlying | ||
| operating system and integration with other tools. | ||
| PowerShell is guaranteed to be case-insensitive on all systems for the | ||
| following areas: | ||
|
|
||
| ## On all systems | ||
| - Variable names | ||
| - Operator names | ||
| - Non-dictionary member-access | ||
| - Command discovery of PowerShell commands and aliases. This excludes | ||
| ExternalScript and Application commands. | ||
| - Parameter names and aliases | ||
| - PowerShell language keywords | ||
| - `using namespace` statements | ||
| - Type literals | ||
| - `#Requires` statements | ||
| - Comment-based help keywords | ||
| - PSProvider names | ||
| - PSDrive names | ||
| - Scope modifiers | ||
|
|
||
| - PowerShell variables are case-insensitive | ||
|
|
||
| Variable names have no interaction between them and the underlying operating | ||
| system. PowerShell treats them case-insensitively. | ||
| ## Special cases | ||
|
|
||
| - Module names are case-insensitive (with exceptions) | ||
|
|
||
| The _name_ of the module is purely a PowerShell concept and treated | ||
| case-insensitively. However, there is a strong mapping to a foldername, which | ||
| can be case-sensitive in the underlying operating system. Importing two| | ||
| can be case-sensitive in the underlying operating system. Importing two | ||
| modules with the same case-insensitive name has the same behavior as | ||
| importing two modules with the same name from different paths. | ||
|
|
||
| The name of a module is stored in the session state using the case by which | ||
| it was imported. The name, as stored in the session state, is used | ||
| `Update-Help` when looking for new help files. | ||
| The web service that serves the help files for Microsoft uses a | ||
| case-sensitive filesystem. When the case of the imported name of the module | ||
| doesn't match, `Update-Help` can't find the help files and reports an error. | ||
| `Update-Help` when looking for new help files. The web service that serves | ||
sdwheeler marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| the help files for Microsoft uses a case-sensitive file system. When the case | ||
| of the imported name of the module doesn't match, `Update-Help` can't find | ||
| the help files and reports an error. | ||
|
|
||
| - [PS providers][05]: | ||
|
|
||
| The `FileSystem` and `Environment` providers are case-sensitive on | ||
| non-Windows systems. Generally, operations involving paths or environment | ||
| variables are case-sensitive on such systems. | ||
|
|
||
| However, [wildcard matching][09] by [provider cmdlets][02] is | ||
| case-insensitive, irrespective of the system. | ||
|
|
||
| ```powershell | ||
| [void] (New-Item -Path Temp:foo.txt -Force) | ||
michaeltlombardi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (Get-Item -Path Temp:FOO.txt).Name | ||
| # Get-Item: Cannot find path 'Temp:/FOO.txt' because it does not exist. | ||
| (Get-Item -Path Temp:F[O]*.txt).Name | ||
| # foo.txt | ||
| (Get-Item -Path Env:hOME).Name | ||
| # Get-Item: Cannot find path 'Env:/hOME' because it does not exist. | ||
| (Get-Item -Path Env:hOM[E]).Name | ||
| # HOME | ||
| ``` | ||
|
|
||
| - Parameter set names are case-sensitive. | ||
|
|
||
| The `DefaultParameterSetName` case must be identical to `ParameterSetName`. | ||
|
|
||
| - .NET methods often exhibit case-sensitive behavior by default. | ||
|
|
||
| Examples include: | ||
|
|
||
| - Equivalent .NET methods (without explicit opt-in) for common PowerShell | ||
| operators such as: | ||
| - `Array.Contains()`, `String.Contains()`, `String.Replace()`, | ||
| `Regex.Match()`, `Regex.Replace()` | ||
| - Reflection; member names must use the correct case. | ||
| - Non-literal dictionary instantiation. For example: | ||
| - `[hashtable]::new()` has case-sensitive keys, whereas a hashtable | ||
| literal `@{}` has case-insensitive keys. | ||
| - `[ordered]::new()` has case-sensitive keys, whereas a `[ordered] @{}` has | ||
| case-insensitive keys. The `[ordered]` type _accelerator_ isn't available | ||
| in PowerShell v5.1 and earlier. | ||
| - Explicitly calling `Enum.Parse()` is case-sensitive by default, whereas | ||
| PowerShell typically handles enums in a case-insensitive manner. | ||
|
|
||
| - `-Unique` cmdlets: | ||
| - [`Select-Object -Unique`][21] and [`Get-Unique`][15] are case-sensitive by | ||
| default. The [`-CaseInsensitive`][20] switch was added in PS v7.4. | ||
| - [`Sort-Object -Unique`][25] is case-insensitive by default, but has always | ||
| had [`-CaseSensitive`][24] switch. | ||
sdwheeler marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - [`Compare-Object`][11] is case-insensitive by default, but has a | ||
| [`-CaseSensitive`][12] switch. Comparison of `[char]` types is case-sensitive | ||
| by default. String comparison is case-insensitive by default. | ||
|
|
||
| ```powershell | ||
| # Compare strings - Equal (no output) | ||
| Compare-object -ReferenceObject a -DifferenceObject A | ||
| # Compare chars - Different (output) | ||
| Compare-object -ReferenceObject ([char] 'a') -DifferenceObject ([char] 'A') | ||
| ``` | ||
|
|
||
| - [`ConvertFrom-Json -AsHashtable`][13]: | ||
| - `-AsHashtable` was added in PS v6. In PS v7.3, a change was made to treat | ||
| JSON keys as case-sensitive when this parameter is specified. | ||
| - With the parameter, an object of type | ||
| [`Management.Automation.OrderedHashtable`][27] is emitted, which has | ||
| case-sensitive keys. | ||
| - Without the parameter, JSON keys are treated as case-insensitive. Output | ||
| is a custom object; last case-insensitive key wins. | ||
| - https://github.com/PowerShell/PowerShell/issues/19928 | ||
|
|
||
| - [`Group-Object`][16]: | ||
| - Case-insensitive by default, but does have a [`-CaseSensitive`][18] | ||
| switch. | ||
| - In Windows PowerShell v5.1, `-CaseSensitive` and [`-AsHashtable`][17] | ||
| produces a case-insensitive hashtable. Duplicate keys result in an error. | ||
|
|
||
| ```powershell | ||
| [pscustomobject] @{ Foo = 'Bar' }, [pscustomobject] @{ Foo = 'bar' } | | ||
| Group-Object -Property Foo -CaseSensitive -AsHashtable | ||
| ``` | ||
| ```Output | ||
| Group-Object : The objects grouped by this property cannot be expanded | ||
| because there is a key duplication. Provide a valid value for the | ||
| property, and then try again. | ||
| At line:2 char:11 | ||
| + Group-Object -Property Foo -CaseSensitive -AsHashtable | ||
| + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| + CategoryInfo : InvalidArgument: (:) [Group-Object], Exception | ||
| + FullyQualifiedErrorId : The objects grouped by this property | ||
| cannot be expanded because there is a key duplication. Provide a valid | ||
| value for the property, and then try again.,Microsoft.PowerShell.Comman | ||
| ds.GroupObjectCommand | ||
| ``` | ||
| - In PowerShell v7 and higher, `-CaseSensitive` and `-AsHashtable` produces a | ||
| case-sensitive hashtable. No error occurs with duplicate keys. | ||
| ```powershell | ||
| [pscustomobject] @{ Foo = 'Bar' }, [pscustomobject] @{ Foo = 'bar' } | | ||
| Group-Object -Property Foo -CaseSensitive -AsHashtable | ||
| ``` | ||
| ```Output | ||
| Name Value | ||
| ---- ----- | ||
| Bar {@{Foo=Bar}} | ||
| bar {@{Foo=bar}} | ||
| ``` | ||
| - [`Select-String`][22]: | ||
| - Case-insensitive by default, but does have a [`-CaseSensitive`][23] switch. | ||
| - [`Get-Command`][14] and command discovery/invocation: | ||
| - On case-sensitive file systems, discovery and invocation of | ||
| `ExternalScript` and `Application` command are case-sensitive. | ||
| - `Get-Command` wildcard matching with these types is also case-sensitive. | ||
| - All other [`CommandTypes`][26] are case-insensitive. | ||
| - [Comparison operators][03]: | ||
| - By default, operators are case-insensitive. | ||
| - `-c*` operators are case-sensitive. | ||
| - `-i*` operators are case-insensitive. | ||
| - `-replace`/`-ireplace` is case-insensitive by default, _except_ with [named | ||
| capture groups][01], which are case-sensitive. | ||
| ```powershell | ||
| 'Bar' -replace '(?<a>a)', '${a}${a}' | ||
| # Baar | ||
| 'Bar' -replace '(?<a>a)', '${A}${A}' | ||
| # B${A}${A}r | ||
| ``` | ||
| - [`-split` operator](about_split): | ||
| - `-split` and `-isplit` are case-insensitive. | ||
| - `-csplit` is case-sensitive, _unless_ the `IgnoreCase` option is specified. | ||
| ```powershell | ||
| 'Bar' -csplit 'A', 0 | ||
| # Bar | ||
| 'Bar' -csplit 'A', 0, 'IgnoreCase' | ||
| # B | ||
| # r | ||
| ``` | ||
| - [Tab completion][07]: | ||
| - On case-sensitive file systems, tab completion and globbing are both | ||
| case-insensitive. For example, `TabExpansion2 -inputScript ./foo` will | ||
| complete to `./Foo.txt` on Linux. | ||
| - [`using`][08] statement: | ||
| - On case-sensitive file systems, `using module` and `using assembly` are | ||
| case-sensitive when a path is specified. | ||
| - `using module` with just a module name is case-insensitive. | ||
| - `using namespace` is always case-insensitive. | ||
| - [Special characters][06]: | ||
| - Escape sequences like `` `n `` are case-sensitive. | ||
| ## See also | ||
| - [about_Environment_Variables](about_Environment_Variables.md) | ||
| - [Import-Module](xref:Microsoft.PowerShell.Core.Import-Module) | ||
| - [about_Environment_Variables][04] | ||
| - [Import-Module][19] | ||
| <!-- link references --> | ||
| [01]: /dotnet/standard/base-types/substitutions-in-regular-expressions#substituting-a-named-group | ||
| [02]: /powershell/scripting/developer/provider/provider-cmdlets | ||
| [03]: about_comparison_operators.md | ||
| [04]: about_Environment_Variables.md | ||
| [05]: about_providers.md | ||
| [06]: about_special_characters.md | ||
| [07]: about_tab_expansion.md | ||
| [08]: about_using.md | ||
| [09]: about_wildcards.md | ||
| [11]: xref:Microsoft.PowerShell.Core.Compare-Object | ||
| [12]: xref:Microsoft.PowerShell.Core.Compare-Object#-casesensitive | ||
| [13]: xref:Microsoft.PowerShell.Core.ConvertFrom-Json#-ashashtable | ||
| [14]: xref:Microsoft.PowerShell.Core.Get-Command | ||
| [15]: xref:Microsoft.PowerShell.Core.Get-Unique | ||
| [16]: xref:Microsoft.PowerShell.Core.Group-Object | ||
| [17]: xref:Microsoft.PowerShell.Core.Group-Object#-ashashtable | ||
| [18]: xref:Microsoft.PowerShell.Core.Group-Object#-casesensitive | ||
| [19]: xref:Microsoft.PowerShell.Core.Import-Module | ||
| [20]: xref:Microsoft.PowerShell.Core.Select-Object#-caseinsensitive | ||
| [21]: xref:Microsoft.PowerShell.Core.Select-Object#-unique | ||
| [22]: xref:Microsoft.PowerShell.Core.Select-String | ||
| [23]: xref:Microsoft.PowerShell.Core.Select-String#-casesensitive | ||
| [24]: xref:Microsoft.PowerShell.Core.Sort-Object#-casesensitive | ||
| [25]: xref:Microsoft.PowerShell.Core.Sort-Object#-unique | ||
| [26]: xref:System.Management.Automation.CommandTypes | ||
| [27]: xref:System.Management.Automation.OrderedHashtable | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.