Parameter binding between scripts

Welcome Forums General PowerShell Q&A Parameter binding between scripts

Viewing 2 reply threads
  • Author
    Posts
    • #193556
      Participant
      Topics: 3
      Replies: 5
      Points: 119
      Rank: Participant
      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:

      **

      **

      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.

       

    • #193562
      Moderator
      Topics: 5
      Replies: 237
      Points: 1,320
      Helping Hand
      Rank: Community Hero

      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.

    • #193568
      Participant
      Topics: 3
      Replies: 5
      Points: 119
      Rank: Participant

      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.

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

Viewing 2 reply threads
  • The topic ‘Parameter binding between scripts’ is closed to new replies.