Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Having hard time with Get-Member

Reply
 
Old 11-22-2008   #1 (permalink)
Personne


 
 

Having hard time with Get-Member

The way I see it so far is that Get-member is a very powerful and
helpful command when playing with powershell

I'm still a newbie with Powershell, but I'm having sometimes hard time
to understand few things

PS > "hello".length
5

I've learnt about .length by typing
PS > "hello" | get-member

and I found the property length
Length Property System.Int32 Length {get;}

I'm reading Power Shell Pocket reference, and I found this example:

PS >(dir).Count
2276

So I thought that I will find the count property of dir (or get-
childintem) by typing
PS > dir | get-member
or
PS > child-item | get-member

but I'm cannot find it

Is this normal ?
Am I missing something ?

My System SpecsSystem Spec
Old 11-22-2008   #2 (permalink)
tojo2000


 
 

Re: Having hard time with Get-Member

On Nov 22, 9:13*am, Personne <cpdiv...@xxxxxx> wrote:
Quote:

> The way I see it so far is that Get-member is a very powerful and
> helpful command when playing with powershell
>
> I'm still a newbie with Powershell, but I'm having sometimes hard time
> to understand few things
>
> PS > "hello".length
> 5
>
> I've learnt about .length by typing
> PS > "hello" | get-member
>
> and I found the property length
> Length * * * * * Property * * * * * * *System.Int32 Length {get;}
>
> I'm reading Power Shell Pocket reference, and I found this example:
>
> PS >(dir).Count
> 2276
>
> So I thought that I will find the count property of dir (or get-
> childintem) by typing
> PS > dir | get-member
> or
> PS > child-item | get-member
>
> but I'm cannot find it
>
> Is this normal ?
> Am I missing something ?
One of the weird quirks about PowerShell is that an operation that
returns an array will automatically just return the object instead of
the array if there is only one element. Count is a property of an
array. If only one item is returned, then Count doesn't exist.

You can force it to consider the output to be an array by putting @()
around the value.

Example:

(dir some_exact_filename.txt)

Will not have a Count property, but

@(dir some_exact_filename.txt)

will have a Count property.
My System SpecsSystem Spec
Old 11-22-2008   #3 (permalink)
Personne


 
 

Re: Having hard time with Get-Member

How did you figure that out ?

So following you idea, I tried this

(dir some_exact_filename.txt) | get-member *co*
and
@(dir some_exact_filename.txt) | get-member *co*

and no count property show up !!!

I'm sad, very sad

My System SpecsSystem Spec
Old 11-23-2008   #4 (permalink)
tojo2000


 
 

Re: Having hard time with Get-Member

On Nov 22, 4:04*pm, Personne <cpdiv...@xxxxxx> wrote:
Quote:

> How did you figure that out ?
>
> So following you idea, I tried this
>
> (dir some_exact_filename.txt) *| get-member *co*
> and
> @(dir some_exact_filename.txt) *| get-member *co*
>
> and no count property show up !!!
>
> I'm sad, very sad
Ah, this is another caveat. When you pass an array to a pipe, Get-
Member grabs each item INSIDE the array and processes it. To see the
array itself you need to use the input parameter.

Try this:
gm -in @(dir some_exact_filename.txt)

And in my case I found it out by trial and error, but I hope someone
out there has a more authoritative (and less frustrating) source to
suggest.
My System SpecsSystem Spec
Old 11-23-2008   #5 (permalink)
Personne


 
 

Re: Having hard time with Get-Member

Tojo2000 and Shay thank you

Because I like to learn, I would like to know where I can find about
this ,@(xxx) syntax.
I knew about @(xxx) but never see ,@(xxx) before today



My System SpecsSystem Spec
Old 11-23-2008   #6 (permalink)
Shay Levy [MVP]


 
 

Re: Having hard time with Get-Member


Check the Windows PowerShell Team Blog:
http://blogs.msdn.com/powershell/arc...owershell.aspx



---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar



P> Tojo2000 and Shay thank you
P>
P> Because I like to learn, I would like to know where I can find about
P> this ,@(xxx) syntax.
P> I knew about @(xxx) but never see ,@(xxx) before today


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Add-Member not Adding a member PowerShell
my hard disk is working all the time Vista hardware & devices
Hard drives work all the time Vista General
Why does the hard drive run all the time??? Vista General
Being a member of a workgroup and domain at the same time Vista networking & sharing


Vista Forums 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 Ltd

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