Empty object evaluates as $True??


i can't figure out going on here.  have appears (to me) empty object: 

$adsiobj = new-object system.directoryservices.directorysearcher([adsi]""

)  
 

$adsiobj.filter = "(&(objectcategory=person)(samaccountname=fakename))"

$adsiobj.findall()

$adsiobj.findall().count

0

$adsiobj.findall() | gm

get-member : no object has been specified get-member cmdlet.
@ line:1 char:23
+ $adsiobj.findall() |gm <<<<
    + categoryinfo          : closeerror: (:) [get-member], invalidoperationexception
    + fullyqualifiederrorid : noobjectingetmember,microsoft.powershell.commands.getmembercommand

 

but evaluates $true:  if ($adsiobj.findall()) {$true}

true

 

can enlighten me?

 


 

 

 

$adsiobj.findall() returning collection.  it's empty collection, it's still collection.

($adsiobj.findall()).gettype()

ispublic isserial name                                     basetype                  
-------- -------- ----                                     --------                  
true     false    searchresultcollection                   system.marshalbyrefobject 

when send arrray or collection  through pipeline, "unrolls" collection stream of individual objects.  since collection emtpy, nothing got sent get-member, hence error message.

to see properties of collection, have this:

get-member -inputobject $adsiobj

the collection evaluates $true, because exists.


[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Group Policy Event ID 1058 Error Code 1326 (The user name or password is incorrect)

Suspicious event log Event ID: 4905

DCOM received error "2147746132" from...