Skip to content

Export-Hashtable

SYNOPSIS

Exports a hashtable to a specified file in PSD1, PS1, or JSON format.

SYNTAX

Export-Hashtable [-Hashtable] <Hashtable> [-Path] <String> [-ProgressAction <ActionPreference>]
 [<CommonParameters>]

DESCRIPTION

This function takes a hashtable and exports it to a file in one of the supported formats: PSD1, PS1, or JSON. The format is determined based on the file extension provided in the Path parameter. If the extension is not recognized, the function throws an error. This function supports pipeline input.

EXAMPLES

EXAMPLE 1

$myHashtable = @{ Key = 'Value'; Number = 42 }
$myHashtable | Export-Hashtable -Path 'C:\config.psd1'

Exports the hashtable to a PSD1 file.

EXAMPLE 2

$myHashtable = @{ Key = 'Value'; Number = 42 }
Export-Hashtable -Hashtable $myHashtable -Path 'C:\script.ps1'

Exports the hashtable as a PowerShell script that returns the hashtable when executed.

EXAMPLE 3

$myHashtable = @{ Key = 'Value'; Number = 42 }
Export-Hashtable -Hashtable $myHashtable -Path 'C:\data.json'

Exports the hashtable as a JSON file.

PARAMETERS

-Hashtable

The hashtable to export.

Type: Hashtable
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False

-Path

The file path where the hashtable will be exported.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

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

INPUTS

OUTPUTS

void

NOTES

This function does not return an output. It writes the exported data to a file.

https://psmodule.io/Export/Functions/Export-Hashtable/