0

This a very newbie powershell question, but I couldn't find what's wrong in my little script, I appreciate if anyone can help on this. So, my function is as basic as :

cls
function Matchstring  ($source, $compare) {

write-host -ForegroundColor Green ("Comparing " + $compare +' and '+ $source)
}

Matchstring('Test1', 'Test2')

But the result I get is Comparing and Test1 Test2 instead of Comparing Test1 and Test2

mklement0
  • 382,024
  • 64
  • 607
  • 775
Aziz Azizos
  • 15
  • 1
  • 6
  • Function parameters in calls are space separated, not comma separated like in function definition. – vonPryz Nov 11 '20 at 21:15
  • This is completley detailed in the Powershell Help files. [about_Parameters - PowerShell | Microsoft Docs](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parameters) --- [about_Parameter_Sets - PowerShell | Microsoft Docs](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parameter_sets). This [Matchstring('Test1', 'Test2')] is wrong. You cannot use comas or those parens. It's this [Matchstring -source 'Source' -compare 'Compare'] – postanote Nov 11 '20 at 22:05

1 Answers1

0

No comma and no parenthesis in the call line.

Matchstring 'Test1' 'Test2'
shawnzzzy
  • 16
  • 5