1

Why do I have difference in output?

$f = Get-WindowsFeature
$f[1].GetType()
$f[1]

output

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

Name                      : ADCS-Cert-Authority
DisplayName               : Certification Authority
Description               : Certification Authority (CA) is used to issue and manage certificates. Multiple CAs can be linked to form a public key infrastructure.
...

and

$f = Get-WindowsFeature   
$f[1]

output

Display Name                                    Name                       Install State
------------                                    ----                       -------------
[ ] Certification Authority                     ADCS-Cert-Authority            Available

Also get more verbose output from $lines.GetType() if don't remove $f[1].

$f = Get-WindowsFeature
$f[1]

$lines = Get-Content featuresinarray.txt | Where {$_ -notmatch '^\s+$'} 
$lines.GetType()

output

Display Name                                    Name                       Install State
------------                                    ----                       -------------
[ ] Certification Authority                     ADCS-Cert-Authority            Available

Module                     : CommonLanguageRuntimeLibrary
Assembly                   : mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
TypeHandle                 : System.RuntimeTypeHandle
DeclaringMethod            : 
BaseType                   : System.Array

But now if I add $f.GetType() after $f = Get-WindowsFeature I get short output from both $lines.GetType() and $f.GetType():

True     True     Object[]                                 System.Array

If I add $f.GetType() after $lines.GetType() then I have 2 times verbose output of Array class in ouput. So why this is happening?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Lavandil
  • 153
  • 2
  • 5
  • 14
  • 1
    whats the difference you got? – Ranadip Dutta Feb 06 '17 at 15:03
  • @Ranadip Dutta I updated the question – Lavandil Feb 06 '17 at 15:24
  • so it is giving properly only. See the base type along with the other information. Whats your confusion ? Could you please post the two outputs and tell what exactly is the confusion – Ranadip Dutta Feb 06 '17 at 15:26
  • I don't understand what is the reason that I get short or verbose output from $f[0] or from "some variable".GetType(). Output is just one row definition of class/object or each property definition like Format-List -Property * generates – Lavandil Feb 06 '17 at 15:44
  • 4
    [Related](https://blogs.msdn.microsoft.com/powershell/2006/04/29/how-powershell-formatting-and-outputting-really-works/). [Also related](http://stackoverflow.com/a/40344479/1630171). – Ansgar Wiechers Feb 06 '17 at 15:45
  • @Lavandil: Check Ansgar Links. Its properly explained – Ranadip Dutta Feb 06 '17 at 15:46

0 Answers0