1

I am learning PowerShell and I had a question about passing parameters. I wanted to create a function that allows you to pass in 2 integer parameters. It takes the first parameter and 'raises' it to the magnitude of the second number. ie get-power(3,2) would be 9. It appears that when I run this function that it creates an array. How do I either use the values inside the array to complete the function or am I missing a step or concept.

function get-power{
  Param
 (
    [Parameter(Mandatory=$true, Position =0)]
    [int]$arg1,
    [Parameter(Mandatory=$true, Position= 1)]
    [int]$arg2
    )
      [math]::Pow([int]$arg1, [int]$arg2)
}
3
  • Actually, it should return a double. You can cast it as in [int] if you want if the answer is not bigger than an int. Commented Oct 3, 2017 at 21:20
  • You call the function like so: get-power 3 2. Your function works as is. Commented Oct 3, 2017 at 21:25
  • 1
    Omgosh, I was trying to return it as get-power(3,2) Thank you so much Commented Oct 3, 2017 at 22:00

1 Answer 1

3

Just do it:

function get-power([int]$arg1, [int]$arg2)
{
    [math]::Pow([int]$arg1, [int]$arg2)
}


$result=get-power 3 2
$result
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.