我有4个变量的集合,如(Get-Variable | Where Name -Match "^astr.*")
,数组和文本字符串变量混合在一起。
出于比较的原因,我想查看它们各自的类型信息。如果我输入
$astr2.GetType()
我得到的是BaseType'System.Array'。
对于
$astr3.GetType()
我得到了'System.Object',所以我看到了它们类型的区别。
但是,请一目了然地
Get-Variable | Where Name -Match "^astr.*" | Select {$_.GetType().BaseType}
我四次获得“ System.Object”,但没有不同的值。
也
Get-Variable | Where Name -Match "^astr.*" | %{$_.GetType()}, or
Get-Variable | Where Name -Match "^astr.*" | %{$_.GetType().BaseType}
不给出预期。为什么迭代不起作用?
答案 0 :(得分:1)
这对我有用:
Get-Variable | Where Name -Match "^astr.*" | Select {$_.Value.GetType()}
答案 1 :(得分:0)
Dank u wel,Gert-Jan和Jeroen!添加“ .Value”可以按预期工作,并且完全得到Jeroen的注释的前13个单词的支持...很大的帮助!