Skip to content

Latest commit

 

History

History
31 lines (19 loc) · 871 Bytes

UseLiteralInitializerForHashtable.md

File metadata and controls

31 lines (19 loc) · 871 Bytes

UseLiteralInitializerForHashtable

Severity Level: Warning

Description

Creating a hashtable by either [hashtable]::new() or New-Object -TypeName hashtable will create a hashtable wherein the keys are looked-up in a case-sensitive manner, unless an IEqualityComparer object is passed as an argument. However, PowerShell is case-insensitive in nature and it is best to create hashtables with case-insensitive key look-up. This rule is intended to warn the author of the case-sensitive nature of the hashtable if he/she creates a hashtable using the new member or the New-Object cmdlet.

How to Fix

Use the full cmdlet name and not an alias.

Example

Wrong???

$hashtable = [hashtable]::new()

Wrong???

$hashtable = New-Object -TypeName hashtable

Correct:

$hashtable = @{}