Function 如何使用powershell函数参数

Function 如何使用powershell函数参数,function,powershell,Function,Powershell,这是一个非常新的powershell问题,但我无法在我的小脚本中找到问题所在,如果有人能在这方面提供帮助,我将不胜感激。因此,我的功能基本如下: cls function Matchstring ($source, $compare) { write-host -ForegroundColor Green ("Comparing " + $compare +' and '+ $source) } Matchstring('Test1', 'Test2') 但是我得到的

这是一个非常新的powershell问题,但我无法在我的小脚本中找到问题所在,如果有人能在这方面提供帮助,我将不胜感激。因此,我的功能基本如下:

cls
function Matchstring  ($source, $compare) {

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

Matchstring('Test1', 'Test2')

但是我得到的结果是比较Test1和Test2,而不是比较Test1和Test2,调用行中没有逗号和括号

Matchstring 'Test1' 'Test2'

调用中的函数参数是以空格分隔的,而不是像函数定义中那样以逗号分隔的。这在Powershell帮助文件中有详细说明。--。此[Matchstring('Test1','Test2')]错误。你不能使用comas或那些paren。这是[Matchstring-source'source'-compare'compare']