Windows Vista Forums

Print out arbitrary properties of objects
  1. #1


    =?Utf-8?B?SkogU3RyZWljaGVyLUJyZW1lcg==?= Guest

    Print out arbitrary properties of objects

    I’m quite new to powershell and am intrigued by the possibilities. As I’m
    learning the new syntax I have been unable to determine how to print out an
    arbitrary property of an object. For example, I’m exploring the get-process
    command(let). I know that by doing a “get-process|get-member –type all”
    this will print out all the possible methods and properties available with an
    object. Now, for example, I would like to drill into the “ProcessorAffinity”
    of an object. How would I go about displaying this (or any other) property
    or property set?
    Thanks in advance!
    JJ




      My System SpecsSystem Spec

  2. #2


    Alex K. Angelopoulos [MVP] Guest

    Re: Print out arbitrary properties of objects

    You can use the format-* cmdlets with the array of properties you want to
    display. For example:
    Get-Process | Format-Table -Property Name,ProcessorAffinity
    To force column autosizing, you can add Format-Table's AutoSize parameter:
    Get-Process | Format-Table -Property Name,ProcessorAffinity -AutoSize

    "JJ Streicher-Bremer" <JJStreicherBremer@discussions.microsoft.com> wrote in
    message news:AE421B52-C608-40B4-8BD9-808E023CA369@microsoft.com...
    > I'm quite new to powershell and am intrigued by the possibilities. As I'm
    > learning the new syntax I have been unable to determine how to print out
    > an
    > arbitrary property of an object. For example, I'm exploring the
    > get-process
    > command(let). I know that by doing a "get-process|get-member -type all"
    > this will print out all the possible methods and properties available with
    > an
    > object. Now, for example, I would like to drill into the
    > "ProcessorAffinity"
    > of an object. How would I go about displaying this (or any other)
    > property
    > or property set?
    > Thanks in advance!
    > JJ
    >




      My System SpecsSystem Spec

  3. #3


    =?Utf-8?B?ZGFuY2UyZGll?= Guest

    RE: Print out arbitrary properties of objects

    You can drill down to the property you want using the following syntax
    ps> gps | gm -InputObject { $_.name }

    But when i tried it with "$_.ProcessAffinity", it would generate an error
    since there is no object associated the property.(not sure why, can anyone
    explain why ProcessAffinity is null?)

    Also i have found some .NET type related PowerShell team blog posts
    ".NET Types"
    http://blogs.msdn.com/monad/archive/...08/527713.aspx

    "Finding the static methods of a class"
    http://blogs.msdn.com/powershell/arc...f_a_class.aspx

    "Improved Support for WMI"(For finding members for WMI classes)
    http://blogs.msdn.com/powershell/arc...26/647038.aspx

    "Getting MSDN help urls for .NET BCL types and Members"
    http://blogs.msdn.com/powershell/arc...25/583240.aspx

    Have fun surfing .NET types.

    - Sung

      My System SpecsSystem Spec

  4. #4


    JJ Streicher-Bremer Guest

    Re: Print out arbitrary properties of objects

    First off, THANK YOU! It's great to see a community with such active
    members, I'm excited to start digging in more with PS.



    I think the issue you are running into is the property is ProcessorAffinity,
    not ProcessAffinity so I would expect the latter to be null.



    Thanks again!

    JJ



    "dance2die" <dance2die@discussions.microsoft.com> wrote in message
    news:167C0DB1-4A81-4713-9A5B-9B84AB9C5FA4@microsoft.com...
    > You can drill down to the property you want using the following syntax
    > ps> gps | gm -InputObject { $_.name }
    >
    > But when i tried it with "$_.ProcessAffinity", it would generate an error
    > since there is no object associated the property.(not sure why, can anyone
    > explain why ProcessAffinity is null?)
    >
    > Also i have found some .NET type related PowerShell team blog posts
    > ".NET Types"
    > http://blogs.msdn.com/monad/archive/...08/527713.aspx
    >
    > "Finding the static methods of a class"
    > http://blogs.msdn.com/powershell/arc...f_a_class.aspx
    >
    > "Improved Support for WMI"(For finding members for WMI classes)
    > http://blogs.msdn.com/powershell/arc...26/647038.aspx
    >
    > "Getting MSDN help urls for .NET BCL types and Members"
    > http://blogs.msdn.com/powershell/arc...25/583240.aspx
    >
    > Have fun surfing .NET types.
    >
    > - Sung




      My System SpecsSystem Spec

  5. #5


    JJ Streicher-Bremer Guest

    Re: Print out arbitrary properties of objects

    Fantastic!! Thanks for the quick reply.

    JJ

    "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
    news:uDgvIKYtGHA.1512@TK2MSFTNGP03.phx.gbl...
    > You can use the format-* cmdlets with the array of properties you want to
    > display. For example:
    > Get-Process | Format-Table -Property Name,ProcessorAffinity
    > To force column autosizing, you can add Format-Table's AutoSize parameter:
    > Get-Process | Format-Table -Property Name,ProcessorAffinity -AutoSize
    >
    > "JJ Streicher-Bremer" <JJStreicherBremer@discussions.microsoft.com> wrote
    > in message news:AE421B52-C608-40B4-8BD9-808E023CA369@microsoft.com...
    >> I'm quite new to powershell and am intrigued by the possibilities. As
    >> I'm
    >> learning the new syntax I have been unable to determine how to print out
    >> an
    >> arbitrary property of an object. For example, I'm exploring the
    >> get-process
    >> command(let). I know that by doing a "get-process|get-member -type all"
    >> this will print out all the possible methods and properties available
    >> with an
    >> object. Now, for example, I would like to drill into the
    >> "ProcessorAffinity"
    >> of an object. How would I go about displaying this (or any other)
    >> property
    >> or property set?
    >> Thanks in advance!
    >> JJ
    >>

    >
    >




      My System SpecsSystem Spec

  6. #6


    =?Utf-8?B?ZGFuY2UyZGll?= Guest

    Re: Print out arbitrary properties of objects

    Not a problem there

    By the way, have you tried to run gm -InputObject {$_} with piped object
    from "ls"?
    ls | gm -InputObject { $_ }
    then you will see properties of both "System.IO.FileInfo" and "DirectoryInfo"
    that is because script block "{ $_ }" argument would go over each object and
    try to get
    distinct object's methods and properties.

    Also,
    ls | gm -InputObject { $_.Parent }
    where "Parent" property exists only in "DirectoryInfo" but not in "FileInfo"
    You still will see members/properties for objDirectory.Parent type
    information.

      My System SpecsSystem Spec

Print out arbitrary properties of objects

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exchange 2007 properties/objects/methods IT Staff PowerShell 1 14 Oct 2009
Comparing objects with arbritrary properties. Michael D. Ober .NET General 3 01 May 2009
select-object not returning properties that are objects Jason PowerShell 5 04 Feb 2008
Limited properties with user objects using Get-QADUser Kari PowerShell 14 17 Jul 2007
Info: Can you create your own objects with custom properties. Brandon Shell PowerShell 8 28 Aug 2006