Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

count

Closed Thread
 
Thread Tools Display Modes
Old 07-15-2008   #1 (permalink)
IT STAFF
Guest


 

count

PS D:\> $directory
\\NOL-A0049001\D$\089228b5520c384a86

$directory | gm ==> returns system string.

In the above, there is a record.

If i do a $directory.count, it gives $null and not ONE

How do i ensure there is a scalar value in the $directory.count ?



Old 07-15-2008   #2 (permalink)
IT STAFF
Guest


 

Re: count

Try it myself :

$mycount = $directory | measure-object -property length -sum

$mycount.count ==> at least it gives a number count.

Let me know if u guys have other solutions.


"IT STAFF" <jkklim@xxxxxx> wrote in message
news:uB24cbk5IHA.3420@xxxxxx
Quote:

> PS D:\> $directory
> \\NOL-A0049001\D$\089228b5520c384a86
>
> $directory | gm ==> returns system string.
>
> In the above, there is a record.
>
> If i do a $directory.count, it gives $null and not ONE
>
> How do i ensure there is a scalar value in the $directory.count ?
>
>
>

Old 07-15-2008   #3 (permalink)
tojo2000
Guest


 

Re: count

On Jul 14, 11:48*pm, "IT STAFF" <jkk...@xxxxxx> wrote:
Quote:

> PS D:\> $directory
> \\NOL-A0049001\D$\089228b5520c384a86
>
> $directory | gm ==> returns system string.
>
> In the above, there is a record.
>
> If i do a $directory.count, it gives $null and not ONE
>
> How do i ensure there is a scalar value in the $directory.count ?
Have you tried this?

if ($directory){do something}
Old 07-15-2008   #4 (permalink)
Shay Levy [MVP]
Guest


 

Re: count

Force the result to array so it will always have a count property even when
there is only
one item:

@(dir $directory).count



---
Shay Levy
Windows PowerShell MVP
blog: http://blogs.microsoft.co.il/blogs/ScriptFanatic



IS> PS D:\> $directory
IS> \\NOL-A0049001\D$\089228b5520c384a86
IS> $directory | gm ==> returns system string.
IS>
IS> In the above, there is a record.
IS>
IS> If i do a $directory.count, it gives $null and not ONE
IS>
IS> How do i ensure there is a scalar value in the $directory.count ?
IS>


Old 07-15-2008   #5 (permalink)
Martin Zugec
Guest


 

Re: count

I always use If ($Object) {..}

That is equivalent of "If Exist $Object". You can use same for If
($Object.Count) {...}, which can be translated as "If not $Object.Count is
Nothing"...

Martin

"IT STAFF" <jkklim@xxxxxx> wrote in message
news:uLuduxk5IHA.3480@xxxxxx
Quote:

> Try it myself :
>
> $mycount = $directory | measure-object -property length -sum
>
> $mycount.count ==> at least it gives a number count.
>
> Let me know if u guys have other solutions.
>
>
> "IT STAFF" <jkklim@xxxxxx> wrote in message
> news:uB24cbk5IHA.3420@xxxxxx
Quote:

>> PS D:\> $directory
>> \\NOL-A0049001\D$\089228b5520c384a86
>>
>> $directory | gm ==> returns system string.
>>
>> In the above, there is a record.
>>
>> If i do a $directory.count, it gives $null and not ONE
>>
>> How do i ensure there is a scalar value in the $directory.count ?
>>
>>
>>
>
>
Old 07-16-2008   #6 (permalink)
IT STAFF
Guest


 

Re: count

Tested not working.



"Shay Levy [MVP]" <no@xxxxxx> wrote in message
news:89228ed23682d8cab4825a8667bc@xxxxxx
Quote:

> Force the result to array so it will always have a count property even
> when there is only
> one item:
>
> @(dir $directory).count
>
>
>
> ---
> Shay Levy
> Windows PowerShell MVP
> blog: http://blogs.microsoft.co.il/blogs/ScriptFanatic
>
>
>
> IS> PS D:\> $directory
> IS> \\NOL-A0049001\D$\089228b5520c384a86
> IS> $directory | gm ==> returns system string.
> IS> IS> In the above, there is a record.
> IS> IS> If i do a $directory.count, it gives $null and not ONE
> IS> IS> How do i ensure there is a scalar value in the $directory.count ?
> IS>
>

Old 07-16-2008   #7 (permalink)
Kuma
Guest


 

Re: count

PoSh [11] » $directory = "\\NOL-A0049001\D$\089228b5520c384a86"
PoSh [12] » @(dir $directory).count
Get-ChildItem : Cannot find path '\\NOL-A0049001\D$
\089228b5520c384a86' because it does not exist.
At line:1 char:6
+ @(dir <<<< $directory).count
0

Throws an error because the path doesn't exist, but still shows the
count 0.


PoSh [13] » $directory = "C:\windows\desktop.ini"
PoSh [14] » @(dir $directory).count
1

Found one file and shows count.

Hope that helps.
Old 07-16-2008   #8 (permalink)
Shay Levy [MVP]
Guest


 

Re: count


Is it hidden? If so add -force to dir.


---
Shay Levy
Windows PowerShell MVP
blog: http://blogs.microsoft.co.il/blogs/ScriptFanatic



K> PoSh [11] » $directory = "\\NOL-A0049001\D$\089228b5520c384a86"
K> PoSh [12] » @(dir $directory).count
K> Get-ChildItem : Cannot find path '\\NOL-A0049001\D$
K> \089228b5520c384a86' because it does not exist.
K> At line:1 char:6
K> + @(dir <<<< $directory).count
K> 0
K> Throws an error because the path doesn't exist, but still shows the
K> count 0.
K>
K> PoSh [13] » $directory = "C:\windows\desktop.ini"
K> PoSh [14] » @(dir $directory).count
K> 1
K> Found one file and shows count.
K>
K> Hope that helps.
K>


Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pop ups blocker count Karen Vista security 1 12-31-2007 11:22 AM
KMS Server n count mustangcobra44 Vista General 1 06-08-2007 05:36 AM
Message count Gerry Cornell Vista mail 3 04-04-2007 06:26 AM
Count Thomas PowerShell 3 03-02-2007 01:23 AM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50