Passing an input to a function

Welcome Forums General PowerShell Q&A Passing an input to a function

Viewing 1 reply thread
  • Author
    • #272899
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      Hello, I’m just getting used to Powershell. When I execute the script and enter the numbers 4 and 5 in the 2 queries I expect to get 9 at the end of the script but I only get 45. If I pass these numbers directly hard-coded to the function then there are no problems. Does anyone have an idea what I am doing wrong?


    • #272926
      Topics: 4
      Replies: 427
      Points: 756
      Helping Hand
      Rank: Major Contributor

      What’s happening here is that $a and $b are actually String objects.  So the + operator is joining the string ‘5’ to the string ‘4’ and giving you ’45’.  You need to specify that the inputs are integers:

      Note: although I’ve done that in the function defintion, you could also specify the type elsewhere e.g.

      or even:





Viewing 1 reply thread
  • You must be logged in to reply to this topic.