Import-PowerShellDataFile
从文件导入值, .PSD1
而不调用其内容。
语法
Import-PowerShellDataFile
[-Path] <String[]>
[<CommonParameters>]
Import-PowerShellDataFile
[-LiteralPath] <String[]>
[<CommonParameters>]
说明
cmdlet Import-PowerShellDataFile
从文件中定义的 .PSD1
哈希表中安全地导入键值对。 可以在文件内容上使用 导入 Invoke-Expression
值。
但是, Invoke-Expression
运行 文件中包含的任何代码。 这可能会生成不需要的结果或执行不安全的代码。 Import-PowerShellDataFile
在不调用代码的情况下导入数据。
示例
示例 1:从 PSD1 检索值
此示例检索存储在文件中的 Configuration.psd1
哈希表中的键值对。 Get-Content
用于显示文件的内容 Configuration.psd1
。
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
要导入的文件的路径。 路径中的所有字符都被视为文本值。 不处理通配符。
Type: | String[] |
Aliases: | PSPath, LP |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Path
要导入的文件的路径。 允许使用通配符,但只导入第一个匹配的文件。
Type: | String[] |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | True |