Import-Hashtable¶
SYNOPSIS¶
Imports a hashtable from a specified file.
SYNTAX¶
__AllParameterSets¶
Import-Hashtable [-Path] <string> [<CommonParameters>]
ALIASES¶
This cmdlet has the following aliases, {{Insert list of aliases}}
DESCRIPTION¶
This function reads a file and imports its contents as a hashtable.
It supports .psd1, .ps1, and .json files.
- .psd1 files are imported using Import-PowerShellDataFile.
This process is safe and does not execute any code.
- .ps1 scripts are executed, and their output must be a hashtable.
If the script does not return a hashtable, an error is thrown.
- .json files are read and converted to a hashtable using ConvertFrom-Json -AsHashtable.
This process is safe and does not execute any code.
If the specified file does not exist or has an unsupported format, an error is thrown.
EXAMPLES¶
EXAMPLE 1¶
Import-Hashtable -Path 'C:\config.psd1'
Output:
Name Value
---- -----
Setting1 Enabled
Setting2 42
Imports a hashtable from a .psd1 file.
EXAMPLE 2¶
Import-Hashtable -Path 'C:\script.ps1'
Output:
Name Value
---- -----
Key1 Value1
Key2 Value2
Executes the script and imports the hashtable returned by the .ps1 file.
EXAMPLE 3¶
Import-Hashtable -Path 'C:\data.json'
Output:
Name Value
---- -----
username johndoe
roles {Admin, User}
Reads a JSON file and converts its content into a hashtable.
PARAMETERS¶
-Path¶
Path to the file containing the hashtable.
Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: 0
IsRequired: true
ValueFromPipeline: true
ValueFromPipelineByPropertyName: true
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.String¶
{{ Fill in the Description }}
OUTPUTS¶
hashtable¶
{{ Fill in the Description }}
NOTES¶
A hashtable containing the data from the imported file. The hashtable structure depends on the contents of the imported file.