Parameter binding between scripts

I have two functions that I have included in a module for personal use. I decided to share them as scripts since I know it is more likely that someone will run a script than install a module.
In summary, the first one gets a group of VMs from a VMware vCenter and the second one will look for these VMs' IP addresses and open a RDP session to each one of them.
It works as expected when running the functions and when the second one is a function, but if the second one is the script and not the function I only get the last VM processed.
These are all possible scenarios, with the exact commands I used to run them:

[pre]#Both are functions - Working

Get-SgVm -SGNumber 8 -NoRecursion -Legacy | Connect-VMRDPSession -Datacenter DC1[/pre]

**

[pre]#First in pipeline is script the second one is a function - Working

.\Get-SgVm.ps1 -SGNumber 8 -NoRecursion -Legacy | Connect-VMRDPSession -Datacenter DC1[/pre]

**

[pre]#Both are scripts - Only the last object (VM) of the pipeline gets processed by the second script (only one RDP session is opened)

.\Get-SgVm.ps1 -SGNumber 8 -NoRecursion -Legacy | .\Connect-VMRDPSession.ps1 -Datacenter DC1[/pre]

I ran a Trace-Command with ParameterBinding for the last example. The first script gets all VMs as expected but passes only the last object/VM of the collection to the next script.
I could share the code of these functions and scripts but I think this is more related to the way in which PowerShell processes objects in the pipeline, it seems to be different depending on whether the second element in the pipeline is a script or a function. Is this an expected PowerShell behavior? I am using PS version 5.
 

I don’t think ValueFromPipeline and ValueFromPipelineByPropertyName behave differently for scripts and functions. Can you check the function is properly converted to script?

Thank you.

[quote quote=193562]I don’t think ValueFromPipeline and ValueFromPipelineByPropertyName behave differently for scripts and functions. Can you check the function is properly converted to script?

Thank you.

[/quote]
Thanks Kiran. You are right. It was a missing Process block in the script. I have “fixed” it and it is now working fine.