0

What is the proper way to specify the Name part of the object after a pipe?

Actual Answer Remove the Select from the pipe and go direct such as

dir $staging | Write-Host -ForegroundColor DarkCyan


Setup I am doing a directory listing to the output and I want to use Write-Host to achieve that, but what is need to discriminate out the object boxing and just show Name.

Command dir | select Name | Write-Host -ForegroundColor DarkCyan

but the output to the console looks like this

nce


How can this be done to show just the values of Name?

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
  • In the linked duplicate, I recommend [mklement0's answer](https://stackoverflow.com/a/48888108/3905079) as it's the most complete and up-to-date. – briantist Jun 26 '19 at 17:01
  • @briantist that answer didn't work for `-ExpandProperty Name` gave this error: `Write-Host : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.` – ΩmegaMan Jun 26 '19 at 17:09
  • I put the actual answer in the post since this is closed. – ΩmegaMan Jun 26 '19 at 17:10
  • 1
    `(dir).name | write-host -fore darkcyan` – x0n Jun 26 '19 at 18:46
  • Thanks @xon that is a good one. – ΩmegaMan Jun 26 '19 at 18:51

0 Answers0