1

I have a simple PowerShell expression that returns some object properties. It also returns an object called Computer which has a property called ComputerName which I'm trying to access. The ExpandProperty switch returns all the properties. How do I filter it to return the properties I need?

Here's the expression:

foreach ($computer in $jobinstancestatus.Computers) {
    Select-Object -InputObject $computer -property Status,ResultsPath -ExpandProperty Computer
}

I tried this but it gave an error when I tried to run it.

foreach ($computer in $jobinstancestatus.Computers) {
    Select-Object -InputObject $computer -property Status,ResultsPath (-ExpandProperty Computer).ComputerName
}
Lauraducky
  • 674
  • 11
  • 25
bearaman
  • 1,071
  • 6
  • 23
  • 43

1 Answers1

3

Try this (inside the loop):

Select-Object -InputObject $computer -property Status,ResultsPath,@{N='Computer_ComputerName';E={$_.Computer.ComputerName}}

It's using a "calculated property" to get the value you need.

Mike Shepard
  • 17,466
  • 6
  • 51
  • 69