r/PowerShell • • Jul 28 '26

Question Explain this cursed BS

function Test-Weird1 {

param([array[]]$InputObject)

$obj = $InputObject[0][0]

$obj.GetType().FullName

($obj -is [PSObject])

}

function Test-Weird2 {

param([object[]]$InputObject)

$obj = $InputObject[0]

$obj.GetType().FullName

($obj -is [PSObject])

}

Test-Weird1 (gci)

# System.IO.DirectoryInfo

# False

Test-Weird2 (gci)

# System.IO.DirectoryInfo

# True

# part two

$obj = (gci)[0].PSObject

$obj.GetType() -eq [System.Management.Automation.PSObject]

# True

$obj -is [System.Management.Automation.PSObject]

# False

0 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/Over_Dingo Jul 31 '26

the `inline code` never worked for me

1

u/BlackV Jul 31 '26

Good I guess :) ideally you want to use a code block most of the time