Powershell 4.0无法从psm1导入哈希表

兔八哥

我正在尝试从psm1导入哈希表,但它返回的是空白,没有错误,我使用的是Windows Server 2012 r2,而在具有Powershell 5.1的计算机上,它没有任何问题,是我做错了什么还是不支持它? 4.0?

psm1

$hash =@{ 
    SomeKey = 'SomeValue'
    SomeKey2 = 'SomeValue2'
    SomeKey3 = 'SomeValue3'
}

PS1

Import-Module .\hash.psm1
$hash
Mathias R. Jessen

使用powershell 5.1可以正常工作

我无法使用5.1产生所需的行为

无论如何,您都需要从模块中导出包含变量:

$hash =@{ 
    SomeKey = 'SomeValue'
    SomeKey2 = 'SomeValue2'
    SomeKey3 = 'SomeValue3'
}

Export-ModuleMember -Variable hash

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章