I'm obviously failing to understand the nuances to -PipelineVariable
If I pass Get-NetIPAddress into Get-NetAdapter it shows the associated adapters.
Get-NetIPAddress | Get-NetAdapter -ErrorAction SilentlyContinue
Now if I want to also collect the IP I decided I'd just tack it on
Get-NetIPAddress -PipelineVariable ip | Get-NetAdapter -ErrorAction SilentlyContinue | Select-Object *,@{n='IP';e={$ip.IPAddress}}
However I see the error
Get-NetIPAddress : Cannot retrieve the dynamic parameters for the cmdlet. Object reference not set to an instance of an object.
At line:1 char:5
+ Get-NetIPAddress -PipelineVariable ip
Even just simply running this gets the same error
Get-NetIPAddress -PipelineVariable ip | Get-NetAdapter -ErrorAction SilentlyContinue
This also returns the same error.
Get-NetIPAddress -PipelineVariable ip | Get-NetAdapter -ErrorAction SilentlyContinue | ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
IfDesc = $_.Interfacedescription
IfIndex = $_.ifindex
MAC = $_.macaddress
LinkSpeed = $_.linkspeed
IP = $ip.IPAddress
}
}
Is this not how it was intended to be used? Originally I was using Where-Object to filter against IPv4 address family, but omitted it for this example.
Working around it like this just seems wrong.
foreach($ip in Get-NetIPAddress){
$ip | Get-NetAdapter -ErrorAction SilentlyContinue | ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
IfDesc = $_.Interfacedescription
IfIndex = $_.ifindex
MAC = $_.macaddress
LinkSpeed = $_.linkspeed
IP = $ip.IPAddress
}
}
}