Computing.Net > Forums > Programming > Powershell assistance

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Powershell assistance

Reply to Message Icon

Name: michmoor
Date: March 7, 2008 at 18:56:09 Pacific
OS: XP
CPU/Ram: 1GB
Product: XW6400
Comment:

Hello community,

I have been unable to find semi decent assistance when it comes to powershell online so I figured i would ask you guys. Its really one issue and that is with the "where-object" command. When starting the command how do you know which variable to pass over ? For example if I wanted to do; get-process | where-object {$._................
what would i put after the underscore ? Where do i find the variables needed. I apologize if this is a tad out of scope.



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: March 8, 2008 at 06:39:08 Pacific
Reply:

Your question is not at all out of scope.

It's not $._, but just $_ which gives you the object that's being "piped in." Then you need to add the dot and a property or method of the object. For example, from Microsoft's web page:

Get-Process | Where-Object {$_.handles -gt 200}

handles is a property of the object.


0

Response Number 2
Name: michmoor
Date: March 9, 2008 at 17:24:33 Pacific
Reply:

to check the property or methods of an object I use the "Get-member" command. When i use that for your above example "get-process|get-member" I do not see handles as a property.
Also, if the where-object starts with $_ then were does the period come into play ?

Thanks.


0

Response Number 3
Name: michmoor
Date: March 9, 2008 at 17:33:37 Pacific
Reply:

Also, if i see a property that i want to investagate more, how do i do that. For example if i use "get-service|get-member" and i see a property called "status", how do i find out more about the status property ?

This is alittle better than vbsript =)


0

Response Number 4
Name: klint
Date: March 10, 2008 at 03:44:03 Pacific
Reply:

Here are the first few lines of output when I do get-process|get-member:


TypeName: System.Diagnostics.Process

Name MemberType Definition
---- ---------- ----------
Handles AliasProperty Handles = Handlecount

So handles is just an alternative name for the Handlecount property.

The $_ object is treated just like any other object name syntactically. So the dot goes just after it, as in $_.handles.

I don't know the answer to your question about investigating a property. I use the Powershell User Guide which is in the program group under the Start menu. I'm in the process of learning Powershell myself.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Powershell assistance

Windows PowerShell 1.0 released www.computing.net/answers/programming/windows-powershell-10-released/14875.html

Batch file assistance www.computing.net/answers/programming/batch-file-assistance/13234.html

powershell anyone? www.computing.net/answers/programming/powershell-anyone/15061.html