powershell - 将变量的值作为键添加到HashTable

标签 powershell hashtable powershell-5.0

PowerShell V5 Windows 10

例如,变量 $EmployeeID包含字符串 testValue ,我想简单地使用 $HastTable.Add() 中前一个变量的值功能。它看起来像这样:

$HashTable.Add($EmployeeID, 'some_value')

当然,这不起作用,但希望我清楚我想要实现的目标。

这样,我就可以像往常一样访问该值:
$var = $HashTable.testValue

最佳答案

您做得对,应该能够访问 key 而不会出现任何问题(您只能通过这种方式无法自动完成):

$HashTable = @{ }
$EmployeeID = "testValue"
$HashTable.Add($EmployeeID, 'some_value')
$var = $HashTable.testValue
$var

输出:
some_value

关于powershell - 将变量的值作为键添加到HashTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43178263/

相关文章:

.net - System.Net.ServicePointManager 单例的范围是什么

c# - 从 Powershell 调用的 DLL 使用相对于 Powershell 安装目录的路径。我怎样才能将它设置为其他东西?

hash - 使用redis排序集存储键值对

java - 大数据微基准测试

c# - 检索 CLSID 为 {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} 的组件的 COM 类工厂失败

windows - 如何使用 PowerShell 列出我附近的蓝牙设备

c - mod prime 是否足够好作为 C 中哈希表的哈希函数

azure - 如何在 PowerShell 中使用 AzModule 命令创建 AzureProfile.json 文件?

powershell - PowerShell变量 `${$}`, `${^}`和 `$?`

powershell,如何获取 firefox 窗口标题并关闭其中一个