select members from a file object

Welcome Forums General PowerShell Q&A select members from a file object

This topic contains 1 reply, has 2 voices, and was last updated by

3 years, 11 months ago.

  • Author
  • #23748

    Points: 1
    Rank: Member

    I know this is a stupid question, but I've spent two hours on this. I know I can use the $_ to select the current object in the pipeline, but I don't know how to select a file object in a given folder and then get it's members. for example I have a file named foo.txt and want to access it's extension property.

    I can do (ls foo.txt).extension, but was wondering if there's another, more direct way.

  • #23750

    Points: 0
    Rank: Member

    seems you have already found the most direct way 🙂
    if you can access the current object in the pipeline with $_ then that represents the file object but you dont need to use $_ for file objects

    ls | select-object *
    ls | select Name,Extension

    this will get all the file objects in the current directory. If you are looking for a specific file then you can use -filter or where-object

    ls -filter myfile | select *

The topic ‘select members from a file object’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort