数组值并打印指定的字符数

时间:2015-12-07 08:15:12

标签: powershell

我有一个变量,其中包含一个内容列表作为数组。

$procs = @{name="explorer",type="svchost"}

如何从数组中访问第一个元素(即explorer)的值并存储到变量中? 然后打印该值的前三个字母(即exp)?

1 个答案:

答案 0 :(得分:0)

 # for the first tree letters of the first hash table value
 $NewVar = (@($procs.Values)[0]).Substring(0,3)

 # for the first tree letters of a specific hash table element (name)
 $NewVar = ($procs.name).Substring(0,3)