list of properties to a Select-Object cmdlet as a variable?

Welcome Forums General PowerShell Q&A list of properties to a Select-Object cmdlet as a variable?

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
2 years ago.

  • Author
    Posts
  • #63516

    Participant
    Points: 0
    Rank: Member

    hi is it possible to pass a list of properties to a Select-Object cmdlet as a variable?

  • #63519

    Participant
    Points: 0
    Rank: Member

    Hi Vadim,

    Do you mean so that you don't have to type them out every time? I'm just starting out on this forum so my answer might not be perfect, but storing the property names in an array then using them in select-object sounds like what you mean? (Let's see how I get on with formatting the code!)

    $Properties = @("Handles","ProcessName","Id")
    Get-Process | Select-Object $Properties
    
  • #63522

    Moderator
    Points: 24
    Team Member
    Rank: Member

    Yes, that is possible. You just need to create an array. The array can contain strings representing the names of the properties, expressions (hashtables) to create calculated properties, or both depending on your use case.

    $propertyList = 'Id', 'Name', 'Threads'
    Get-Process | Select-Object -Property $propertyList
    
  • #63558

    Participant
    Points: 0
    Rank: Member

    thanks, just what i needed

The topic ‘list of properties to a Select-Object cmdlet as a variable?’ is closed to new replies.

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