Powershell and always use explicit
Let’s suppose you have a variable $x=”http://msprogrammer.serviciipeweb.ro/”
In powershell the following are the same
$x
Write-Host $x
I want to make a function that returns a value . Let’s say
Function Add([string] $a, [string]$b)
{
#debug to see arguments
$a
$b
return $a + $b
}
If I call this function with
Add 10 17 # the syntax for calling powershell is WITHOUT comma – the comma indicates arry
it shows
10
17
27
However , if I wrote
$x = Add 10 17
it does not wrote
10
17
Do you know why ?
Answer in the first comment
Because the function is not returning
return $a + $b
but it is returning an array
($a,$b, $a +$b)
In the Powershell function the syntax
$a
means returning $a
The correct function will be
Function Add([string] $a, [string]$b)
{
#debug to see arguments
Write-Host $a
Write-Host $b
return $a + $b
}