Select the values of one property on all objects of an array in PowerShell

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Select the values of one property on all objects of an array in PowerShell

Message par ForumBot »

Select the values of one property on all objects of an array in PowerShell
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Select the values of one property on all objects of an array in PowerShell

Message par ForumBot »

I think you might be able to use the `ExpandProperty` parameter of `Select-Object`.

For example, to get the list of the current directory and just have the Name property displayed, one would do the following:

```
ls | select -Property Name

```

This is still returning DirectoryInfo or FileInfo objects. You can always inspect the type coming through the pipeline by piping to [Get-Member](http://technet.microsoft.com/en-us/library/hh849928.aspx) (alias `gm`).

```
ls | select -Property Name | gm

```

So, to *expand* the object to be that of the type of property you're looking at, you can do the following:

```
ls | select -ExpandProperty Name

```

In your case, you can just do the following to have a variable be an array of strings, where the strings are the Name property:

```
$objects = ls | select -ExpandProperty Name

```
Répondre

Revenir à « PowerShell »