Import-PowerShellDataFile
Imports values from a .psd1
file without invoking its contents.
Sintaxis
ByPath (Es el valor predeterminado).
Import-PowerShellDataFile
[[-Path] <string[]>]
[<CommonParameters>]
ByLiteralPath
Import-PowerShellDataFile
[-LiteralPath <string[]>]
[<CommonParameters>]
Description
The Import-PowerShellDataFile
cmdlet safely imports key-value pairs from hashtables defined in a
.psd1
file. The values could be imported using Invoke-Expression
on the contents of the file.
However, Invoke-Expression
runs any code contained in the file. This could produce unwanted
results or execute unsafe code. Import-PowerShellDataFile
imports the data without invoking the
code.
Note
You can only import the first 500 key-value pairs.
Ejemplos
Example 1: Retrieve values from PSD1
This example retrieves the key-value pairs stored in the hashtable kept inside the
Configuration.psd1
file. Get-Content
is used to show the contents of the Configuration.psd1
file.
Get-Content .\Configuration.psd1
$config = Import-PowerShellDataFile .\Configuration.psd1
$config.AllNodes
@{
AllNodes = @(
@{
NodeName = 'DSC-01'
}
@{
NodeName = 'DSC-02'
}
)
}
Name Value
---- -----
NodeName DSC-01
NodeName DSC-02
Parámetros
-LiteralPath
The path to the file being imported. All characters in the path are treated as literal values.
Propiedades del parámetro
Tipo: | String[] |
Valor predeterminado: | None |
Admite caracteres comodín: | False |
DontShow: | False |
Alias: | PSPath, LP |
Conjuntos de parámetros
ByLiteralPath
Posición: | Named |
Mandatory: | True |
Valor de la canalización: | False |
Valor de la canalización por nombre de propiedad: | True |
Valor de los argumentos restantes: | False |
-Path
The path to the file being imported. Wildcards are allowed but only the first matching file is imported.
Propiedades del parámetro
Tipo: | String[] |
Valor predeterminado: | None |
Admite caracteres comodín: | True |
DontShow: | False |
Conjuntos de parámetros
ByPath
Posición: | 0 |
Mandatory: | True |
Valor de la canalización: | False |
Valor de la canalización por nombre de propiedad: | False |
Valor de los argumentos restantes: | False |
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.
Salidas
Hashtable
This cmdlet returns the data from the file as a hash table.