I found a solution here - http://www.eggheadcafe.com/software/aspnet/30677579/count-bug-in-getchilditem.aspx
Classic nuance of PowerShell. When a cmdlet only outputs a single item, you
are dealing with a scalar value. In this case a System.IO.FileInfo object
and it has no count property. As soon as you have multiple items and assign
that to a variable, you get an array. Array's in PowerShell do have a count
property. There are two ways to work with this. First is to use the
measure-object cmdlet - it handles this situation very well:
PS C:\WINDOWS\system32\windowspowershell\v1.0\x> get-childitem |
measure-object
The second way is to force the result into an array like so:
$Files = @(get-childitem)
$Files.count
1
Classic nuance of PowerShell. When a cmdlet only outputs a single item, you
are dealing with a scalar value. In this case a System.IO.FileInfo object
and it has no count property. As soon as you have multiple items and assign
that to a variable, you get an array. Array's in PowerShell do have a count
property. There are two ways to work with this. First is to use the
measure-object cmdlet - it handles this situation very well:
PS C:\WINDOWS\system32\windowspowershell\v1.0\x> get-childitem |
measure-object
The second way is to force the result into an array like so:
$Files = @(get-childitem)
$Files.count
1
>Classic nuance of PowerShell. When a cmdlet only outputs a single item, you
>are dealing with a scalar value. In this case a System.IO.FileInfo object
>and it has no count property. As soon as you have multiple items and assign
>that to a variable, you get an array. Array's in PowerShell do have a count
>property. There are two ways to work with this. First is to use the
>measure-object cmdlet - it handles this situation very well:
>PS C:\WINDOWS\system32\windowspowershell\v1.0\x> get-childitem |
>measure-object
>The second way is to force the result into an array like so:
>$Files = @(get-childitem)
>$Files.count
>1