Import-PowerShellDataFile
Imports values from a .psd1 file without invoking its contents.
構文
ByPath (既定)
Import-PowerShellDataFile
[-Path] <String[]>
[-SkipLimitCheck]
[<CommonParameters>]
ByLiteralPath
Import-PowerShellDataFile
[-LiteralPath] <String[]>
[-SkipLimitCheck]
[<CommonParameters>]
説明
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. By default there is a 500 key limit, but this can be bypassed with the SkipLimitCheck
switch.
例
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
パラメーター
-LiteralPath
The path to the file being imported. All characters in the path are treated as literal values. Wildcard characters aren't processed.
パラメーターのプロパティ
| 型: | String[] |
| 規定値: | None |
| ワイルドカードのサポート: | False |
| DontShow: | False |
| Aliases: | PSPath, LP |
パラメーター セット
ByLiteralPath
| 配置: | 0 |
| 必須: | True |
| パイプラインからの値: | False |
| プロパティ名別のパイプラインからの値: | True |
| 残りの引数からの値: | False |
-Path
The path to the file being imported. Wildcards are allowed but only the first matching file is imported.
パラメーターのプロパティ
| 型: | String[] |
| 規定値: | None |
| ワイルドカードのサポート: | True |
| DontShow: | False |
パラメーター セット
ByPath
| 配置: | 0 |
| 必須: | True |
| パイプラインからの値: | False |
| プロパティ名別のパイプラインからの値: | False |
| 残りの引数からの値: | False |
-SkipLimitCheck
By default Import-PowerShellDataFile imports only 500 keys from a .psd1 file. Use
SkipLimitCheck to import more than 500 keys.
パラメーターのプロパティ
| 型: | Switch |
| 規定値: | False |
| ワイルドカードのサポート: | False |
| DontShow: | False |
パラメーター セット
All
| 配置: | 0 |
| 必須: | False |
| パイプラインからの値: | False |
| プロパティ名別のパイプラインからの値: | False |
| 残りの引数からの値: | 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.
出力
Hashtable
This cmdlet returns the data from the file as a hash table.