我想检索与哈希表TEST中的特定项相关联的值 但它不起作用。你能帮帮我吗?
$TEST=
@{"Monday" = "A"; "Tuesday" = "B"; "Wednesday" = "C"; "Thursday" = "D"; "Friday" = "F"}
$Date = Get-Date
$a = $TEST.Get_Item($Date.get_DayOfWeek())
Write-Host $a
也尝试:
$TEST=
@{"Monday" = "A"; "Tuesday" = "B"; "Wednesday" = "C"; "Thursday" = "D"; "Friday" = "F"}
$Date = Get-Date
$a = $Date.get_DayOfWeek()
$b = TEST.Get_Item($a)
和
$TEST=
@{Monday = "A"; Tuesday = "B"; Wednesday = "C"; Thursday = "D"; Friday = "F"}
$Date = Get-Date
$a = $TEST.Get_Item($Date.get_DayOfWeek())
Write-Host $a
非常感谢!
答案 0 :(得分:2)
DayOfWeek是一个不是字符串的对象,试试这个:
$TEST[(Get-Date).DayOfWeek.ToString()]
答案 1 :(得分:1)
问题是你没有将字符串传递给你的哈希表尝试这样的事情:
$TEST=
@{"Monday" = "A"; "Tuesday" = "B"; "Wednesday" = "C"; "Thursday" = "D"; "Friday" = "F"}
$Date = Get-Date
$a = $TEST[""+$Date.get_DayOfWeek()]
Write-Host $a