How can I access a higher level $_ pipeline variable from a nested pipeline?

I don't have that command, but maybe the -pipelinevariable common parameter can be of use here.

Get-VM -PipelineVariable vm | Get-VHD |
  Select-Object @{n='Name'; e={$vm.name}}, path, parentpath 

You can assign the $_ to a variable and use that:

 1..10 | %{ $a = $_; 1..10 | %{ write-host $a} }

Anyway, consider refactoring your script. It is too nested. Concentrate on readability. It is not always necessary to pipe, you can use a foreach loop if that helps improve readability.

Tags:

Powershell