来自变量集合成员的Powershell GetType

时间:2019-01-31 13:15:23

标签: powershell gettype

我有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}

不给出预期。为什么迭代不起作用?

2 个答案:

答案 0 :(得分:1)

这对我有用:

Get-Variable | Where Name -Match "^astr.*" | Select {$_.Value.GetType()}

答案 1 :(得分:0)

Dank u wel,Gert-Jan和Jeroen!添加“ .Value”可以按预期工作,并且完全得到Jeroen的注释的前13个单词的支持...很大的帮助!

相关问题