Heya Paul, I think it's to do with your use of the Sort-Object expression. I just did some testing with it and it seems that if you pipe in an array with a single object in it, it will return the single object type not in an array. Below is what I tested.
Windows PowerShell Copyright (C) 2009 Microsoft Corporation. All rights reserved. PS C:\Users\Chris> $array = @(5, 3, 6, 8, 0) PS C:\Users\Chris> $array 5 3 6 8 0 PS C:\Users\Chris> $array.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Object[] System.Array PS C:\Users\Chris> $sorted = $array | Sort-Object PS C:\Users\Chris> $sorted 0 3 5 6 8 PS C:\Users\Chris> $sorted.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Object[] System.Array PS C:\Users\Chris> $singleValueArray = @(4) PS C:\Users\Chris> $singleValueArray 4 PS C:\Users\Chris> $singleValueArray.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Object[] System.Array PS C:\Users\Chris> $sorted = $singleValueArray | Sort-Object PS C:\Users\Chris> $sorted 4 PS C:\Users\Chris> $sorted.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Int32 System.ValueType PS C:\Users\Chris> Kind Regards, Chris Tomich On 22 August 2012 07:14, Web Admin <[email protected]> wrote: > Hi all, > > I've written an AD search script and am having a strange problem with > returning the result count when ONE item is returned. > > If one result is returned I get no value displayed for $results.count. > Anything greater than "one" returns the correct count. > > Moreover, in order to return "one" result I need to use *-ge -1* in the > if/else statement. [see below] > > Is this a known issue or can someone tell me what value is/should be > returned for a single result? > > $results = $searcher.FindAll() | Sort-Object@{Expression={$_.Properties.sn}} > if ($results.count -ge -1) > { > # Format our results > cls > Write-Host "Results for $field = $value." $results.count "results found." > ForEach ($user in $results) > { > GetUserInfo ` > $user.properties.sn ` > $user.properties.givenname ` > $user.properties.mail ` > $user.properties.employeeid ` > $user.properties.department ` > $user.properties.telephonenumber ` > $user.properties.wwwhomepage > } > } > else > { > cls > Write-Host "No results found. Try to broaden your search scope." > } > > Regards, > > Paul Noone > > -- > SharePoint Farm Admin/Developer > Infrastructure Team > CEO Sydney > > p: (02) 9568 8461 > f: (02) 9568 8483 > e: [email protected] > w: http://www.ceosyd.catholic.edu.au/ > > > _______________________________________________ > ozmoss mailing list > [email protected] > http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss > >
_______________________________________________ ozmoss mailing list [email protected] http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss
