What type is correct?

by Feb 7, 2012

Hi All.

Test code:

$dir = 'C:TestDir' 
if ([System.IO.Directory]::Exists($dir)) {
    Remove-Item -Path $dir -Recurse
}
New-Item -Path $dir -ItemType directory | Out-Null
foreach ($i in 17..20) {
    for ($m = 0; $m -lt 3; ++$m) {
        foreach ($n in "", "x86", "x64") {
            New-Item -Path "$dir$i.$m$n" -ItemType directory | Out-Null
        }        
    }     
}
 
$x = Get-ChildItem -Path $dir | Select-Object -Property Name
 
'Variant 1:'
$x[0].GetType().FullName
 
'Variant 2:'
$x[0] | Get-Member

Code result:

PS C:GPSMAdminCADscripts> C:UsersuserDesktopTest.ps1

Variant 1:

System.Management.Automation.PSCustomObject

Variant 2:

   TypeName: Selected.System.IO.DirectoryInfo


Name                MemberType          Definition                    

—-                   ———-               ———-                    

Equals               Method                  bool Equals(System.Object obj)

GetHashCode    Method                  int GetHashCode()             

GetType            Method                  type GetType()                

ToString            Method                  string ToString()             

Name                NoteProperty         System.String Name=17.0   

I'm confused: what type of a variable $x: System.Management.Automation.PSCustomObject, or Selected.System.IO.DirectoryInfo?

I know the type of System.IO.DirectoryInfo, but I do not like Selected.System.IO.DirectoryInfo …

Regards