Skip to content

Format-Hashtable

SYNOPSIS

Converts a hashtable to its PowerShell code representation.

SYNTAX

__AllParameterSets

Format-Hashtable [-Hashtable] <IDictionary> [[-IndentLevel] <int>] [<CommonParameters>]

ALIASES

This cmdlet has the following aliases, {{Insert list of aliases}}

DESCRIPTION

Recursively converts a hashtable to its PowerShell code representation. This function is useful for exporting hashtables to .psd1 files, making it easier to store and retrieve structured data.

EXAMPLES

EXAMPLE 1

$hashtable = @{ Key1 = 'Value1' Key2 = @{ NestedKey1 = 'NestedValue1' NestedKey2 = 'NestedValue2' } Key3 = @(1, 2, 3) Key4 = $true } Format-Hashtable -Hashtable $hashtable

Output:

@{
    Key1       = 'Value1'
    Key2       = @{
        NestedKey1 = 'NestedValue1'
        NestedKey2 = 'NestedValue2'
    }
    Key3       = @(
        1
        2
        3
    )
    Key4       = $true
}

PARAMETERS

-Hashtable

The hashtable to convert to a PowerShell code representation.

Type: System.Collections.IDictionary
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: 0
  IsRequired: true
  ValueFromPipeline: true
  ValueFromPipelineByPropertyName: true
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-IndentLevel

The indentation level for formatting nested structures.

Type: System.Int32
DefaultValue: 1
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: 1
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

System.Collections.IDictionary

{{ Fill in the Description }}

OUTPUTS

string

{{ Fill in the Description }}

System.String

{{ Fill in the Description }}

NOTES

A string representation of the given hashtable. Useful for serialization and exporting hashtables to files.