Windows Vista Forums

Newbie Question: Basic select-object Question.

  1. #1


    No Spam Guest

    Newbie Question: Basic select-object Question.

    Newbie alert.

    Hi,

    I am still a beginner at this, so excuse this basic question if it was
    answered.
    I read the docs, search through google and cannot find an answer to
    this.

    How to I capture the string only from the select-object output.

    For example.

    > get-process -name g*
    Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
    ------- ------ ----- ----- ----- ------ -- -----------
    141 23 30480 27500 546 0.45 4928 GOContactSync

    I would like to capture the process name only.


    > get-process -name g* | select-object ProcessName
    ProcessName
    -----------
    GOContactSync

    How do I capture the value only "GOContactSync" and not the
    "ProcessName" headline?

    Any pointers would be greatly appreciated.



    Thanks.


      My System SpecsSystem Spec

  2. #2


    Peter Schneider Guest

    Re: Newbie Question: Basic select-object Question.

    Try the following:

    (get-process -name g*).ProcessName

    or

    $p = get-process -name g* | select-object ProcessName
    $p.ProcessName

    greetings, Peter Schneider

    "No Spam" <nospam@newsgroup> schrieb im Newsbeitrag
    news:7snlc5dj6uifd7mageukqml3a3r679h9en@newsgroup

    > Newbie alert.
    >
    > Hi,
    >
    > I am still a beginner at this, so excuse this basic question if it was
    > answered.
    > I read the docs, search through google and cannot find an answer to
    > this.
    >
    > How to I capture the string only from the select-object output.
    >
    > For example.
    >

    >> get-process -name g*
    >
    > Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
    > ------- ------ ----- ----- ----- ------ -- -----------
    > 141 23 30480 27500 546 0.45 4928 GOContactSync
    >
    > I would like to capture the process name only.
    >
    >

    >> get-process -name g* | select-object ProcessName
    >
    > ProcessName
    > -----------
    > GOContactSync
    >
    > How do I capture the value only "GOContactSync" and not the
    > "ProcessName" headline?
    >
    > Any pointers would be greatly appreciated.
    >
    > Thanks.
    >

      My System SpecsSystem Spec

  3. #3


    rab36 Guest

    RE: Newbie Question: Basic select-object Question.


    Hi,

    Get-Process g*

    returns a collection of process objects with names that start with g

    Select-Object converts each object of this collection to a new custom object
    with the single property ProcessName that is copied from the original process
    objects.

    To investigate this try

    (Get-Process g* | Select-Object ProcessName).GetType()

    and

    Get-Process g* | Select-Object ProcessName | Get-Member

    With the standard formatting the reduced object produces your result.

    Try

    Get-Process g* | ForEach-Object { $_.ProcessName }

    to get a string for every process that starts with g.

    To get the first process only that starts with g you can use

    Get-Process p* | Select-Object -First 1 | ForEach-Object { $_.ProcessName }

    --
    Bernd


    "No Spam" wrote:

    > Newbie alert.
    >
    > Hi,
    >
    > I am still a beginner at this, so excuse this basic question if it was
    > answered.
    > I read the docs, search through google and cannot find an answer to
    > this.
    >
    > How to I capture the string only from the select-object output.
    >
    > For example.
    >

    > > get-process -name g*
    >
    > Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
    > ------- ------ ----- ----- ----- ------ -- -----------
    > 141 23 30480 27500 546 0.45 4928 GOContactSync
    >
    > I would like to capture the process name only.
    >
    >

    > > get-process -name g* | select-object ProcessName
    >
    > ProcessName
    > -----------
    > GOContactSync
    >
    > How do I capture the value only "GOContactSync" and not the
    > "ProcessName" headline?
    >
    > Any pointers would be greatly appreciated.
    >
    > Thanks.
    >
    >

      My System SpecsSystem Spec

  4. #4


    No Spam Guest

    Re: Newbie Question: Basic select-object Question.

    Thank you very much.



    In article <#iRDoBlRKHA.4048@newsgroup>
    "Peter Schneider" <p.schneider@newsgroup> wrote:

    >
    >Try the following:
    >
    >(get-process -name g*).ProcessName
    >
    >or
    >
    >$p = get-process -name g* | select-object ProcessName
    >$p.ProcessName
    >
    >greetings, Peter Schneider
    >
    >"No Spam" <nospam@newsgroup> schrieb im Newsbeitrag
    >news:7snlc5dj6uifd7mageukqml3a3r679h9en@newsgroup

    >> Newbie alert.
    >>
    >> Hi,
    >>
    >> I am still a beginner at this, so excuse this basic question if it was
    >> answered.
    >> I read the docs, search through google and cannot find an answer to
    >> this.
    >>
    >> How to I capture the string only from the select-object output.
    >>
    >> For example.
    >>

    >>> get-process -name g*
    >>
    >> Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
    >> ------- ------ ----- ----- ----- ------ -- -----------
    >> 141 23 30480 27500 546 0.45 4928 GOContactSync
    >>
    >> I would like to capture the process name only.
    >>
    >>

    >>> get-process -name g* | select-object ProcessName
    >>
    >> ProcessName
    >> -----------
    >> GOContactSync
    >>
    >> How do I capture the value only "GOContactSync" and not the
    >> "ProcessName" headline?
    >>
    >> Any pointers would be greatly appreciated.
    >>
    >> Thanks.
    >>

      My System SpecsSystem Spec

Newbie Question: Basic select-object Question.

Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie question Ramsonm Vista General 2 12 Jun 2009
newbie question on SqlDataSource object E. Kwong .NET General 0 25 Aug 2008
Newbie question JasonJFT PowerShell 6 09 Sep 2007
RE: Newbie Question cccstar PowerShell 0 18 Dec 2006
newbie question: using new-object and -FileName J.Marsch PowerShell 2 18 Aug 2006