I've been working on this problem in my personal time for days now...
I need to add a column to the results (Example issue. The code below will eventually error out. [I was just using -Include to test on a single row. My real-world problem uses a different cmdlet, but the same premise).
How do I get what the query was ran for to show up in the resulting table?
ForEach-Object {Get-Service $_.name -DependentServices}
What I need it to look like.
| Status | Name | DisplayName | Parent Name |
|---|---|---|---|
| Stopped | workfolderssvc | Work Folders | WSearch |
| Stopped | WMPNetworkSvc | Windows Media Player Network Sharin... | WSearch |
| Stopped | AarSvc_51453 | Agent Activation Runtime_51453 | AudioEndpointBuilder |
| Stopped | AarSvc | Agent Activation Runtime | AudioEndpointBuilder |
| Running | Audiosrv | Windows Audio | AudioEndpointBuilder |
What the query returns: Status, Name, DisplayName
What I need the query to return: Status, Name, DisplayName, Parent Name
I've tried $row, making a new array by piping through to Select-Object within my Script block, and wrapping $_ in [ $_ ], " $_ ", or "[$_]".
| Select-Object Status, Name, DisplayName, [PSCustomObject]@{Name="Parent Name";Expression={$_.name}}
I'm using Powershell 5.1.
Thank you.