11# Hashtable
22
3- Hashtable is a PowerShell module that simplifies common hashtable operations.
3+ Hashtable is a comprehensive PowerShell module for working with hashtables. It converts hashtables to and from
4+ PSCustomObjects, formats hashtables into readable PowerShell code, merges hashtables with override support, and removes
5+ entries based on specific criteria — simplifying complex hashtable manipulations in your automation workflows.
46
57## Installation
68
@@ -11,7 +13,81 @@ Install-PSResource -Name Hashtable
1113Import-Module -Name Hashtable
1214```
1315
14- If your environment still uses PowerShellGet, install the module with ` Install-Module -Name Hashtable ` instead.
16+ ## Usage
17+
18+ ### Example: Convert a hashtable to a PSCustomObject
19+
20+ Convert a nested hashtable into a PSCustomObject, making it easier to manipulate and explore your data.
21+
22+ ``` powershell
23+ $hashtable = @{
24+ Name = 'Alice'
25+ Age = 30
26+ Contact = @{
27+ Email = 'alice@example.com'
28+ Phone = '123-456-7890'
29+ }
30+ }
31+
32+ $object = $hashtable | ConvertFrom-Hashtable
33+ $object | Format-List
34+ ```
35+
36+ ### Example: Merge hashtables with overrides
37+
38+ Merge a default settings hashtable with user-specified overrides. Values in the override hashtable replace those in the
39+ base hashtable.
40+
41+ ``` powershell
42+ $defaultSettings = @{
43+ Theme = 'Light'
44+ Language = 'en'
45+ Layout = 'Standard'
46+ }
47+ $userSettings = @{
48+ Theme = 'Dark'
49+ Layout = 'Compact'
50+ }
51+
52+ $mergedSettings = $defaultSettings | Merge-Hashtable -Overrides $userSettings
53+ $mergedSettings
54+ ```
55+
56+ ### Example: Format a hashtable as PowerShell code
57+
58+ Convert a hashtable into a nicely formatted PowerShell code representation — useful for exporting configuration to a
59+ ` .psd1 ` file.
60+
61+ ``` powershell
62+ $configuration = @{
63+ Server = 'localhost'
64+ Port = 8080
65+ Credentials = @{
66+ Username = 'admin'
67+ Password = 'P@ssw0rd'
68+ }
69+ Enabled = $true
70+ }
71+
72+ $formattedConfig = $configuration | Format-Hashtable
73+ Write-Output $formattedConfig
74+ ```
75+
76+ ### Example: Remove hashtable entries by criteria
77+
78+ Remove specific entries from a hashtable, such as keys with null or empty values or a key matching a particular name.
79+
80+ ``` powershell
81+ $ht = @{
82+ ValidKey = 'SomeValue'
83+ EmptyKey = ''
84+ RemoveMe = 'Unwanted'
85+ }
86+
87+ # Remove entries with null or empty values and the key named 'RemoveMe'
88+ $ht | Remove-HashtableEntry -NullOrEmptyValues -Keys 'RemoveMe'
89+ $ht
90+ ```
1591
1692## Documentation
1793
@@ -21,9 +97,5 @@ Use PowerShell help and command discovery for module details:
2197
2298``` powershell
2399Get-Command -Module Hashtable
24- Get-Help ConvertTo-Hashtable -Examples
100+ Get-Help -Name ConvertTo-Hashtable -Examples
25101```
26-
27- ## Contributing
28-
29- Issues and pull requests are welcome. Please use the repository issue tracker to report bugs, request features, or discuss improvements.
0 commit comments