将字符串数组传递给PowerShell函数

将字符串数组传递给PowerShell函数,powershell,Powershell,我有一个名为BuildQuery的函数,它将值数组作为参数 Function BuildQuery { Param($start, [String[]] $KeyFields, [String] $Sch, [String] $TableName) $Query = "select $KeyFields from '$Sch'.'$TableName'" } 我想将函数调用为: BuildQuery -start start -KeyFields name, id, age, salary -

我有一个名为BuildQuery的函数,它将值数组作为参数

Function BuildQuery {
Param($start, [String[]] $KeyFields, [String] $Sch, [String] $TableName)
$Query = "select $KeyFields from '$Sch'.'$TableName'"
}
我想将函数调用为:

BuildQuery -start start -KeyFields name, id, age, salary -Sch dbo -TableName Employee 
例如:我想建立一个查询
“从dbo.Employee中选择姓名、id、年龄、工资”
使用PowerShell函数。我使用该函数的唯一原因是我希望反复查看它以生成如下查询。

用于将数组扩展为逗号分隔的列表:

Function BuildQuery {
    Param($start, [String[]] $KeyFields, [String] $Sch, [String] $TableName)
    $Query = "select $($KeyFields -join ',') from '$Sch'.'$TableName'"
}
用于将数组展开为逗号分隔的列表:

Function BuildQuery {
    Param($start, [String[]] $KeyFields, [String] $Sch, [String] $TableName)
    $Query = "select $($KeyFields -join ',') from '$Sch'.'$TableName'"
}

啊,你只比我快了一步:-)@MartinBrandl你已经超过我将近两周了,很高兴能全速回来:-太棒了!这正是我想要的。由于时间限制,我还不能接受答案。。所以等待它结束:)啊,你只比我快了一步:-)@MartinBrandl你已经超过我将近两个星期了,很高兴能全速回来:-太棒了!这正是我想要的。由于时间限制,我还不能接受答案。。所以等待它完成:)