从PowerShell主脚本我想用另一个可选参数和另一个非可选字符串数组参数调用另一个PowerShell脚本。这样的事情(出于解释原因包括功能失调的电话):
$theOptionalParam = "maybe"
$theArrayParam = "A", "B"
$theDirectory = "SomeRelativePath"
#This is the part not working:
.\$theDirectory\SubScript.ps1 -OptionalParam $theOptionalParam -ArrayParam $theArrayParam
SubScript.ps1就像这样开始:
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false)][string]$OptionalParam,
[Parameter(Mandatory=$true)][string[]]$ArrayParam
)
但无论我尝试什么,我都会收到错误或只是数组的第一个值(" A"),其余的都被丢弃。
如何使用动态路径,可选参数和数组参数执行下标更正?
答案 0 :(得分:5)
要将 <script>
function fnfunction(??)
{
//no idea how to do validation for each item
}
</script>
<%
String SQL = "SELECT * FROM TB_BS_WITH UR";
String VALUE1 = "";
String ROW_NO = "";
String COL_NO = "";
DB_Contact.makeConnection();
DB_Contact.executeQuery(SQL);
while(DB_Contact.getNextQuery())
{
VALUE1 = DB_Contact.getColumnString("VALUE1");
ROW_NO = DB_Contact.getColumnString("ROW_NO");
COL_NO = DB_Contact.getColumnString("COL_NO");
%>
<table>
<tr>
<%StringTokenizer st1=n ew StringTokenizer(VALUE1, "^"); while(st1.hasMoreTokens()){%>
<th class="fontSection">
<%=st1.nextToken() %>
</th>
<%}%>
</tr>
<%for(int i=0;i<Integer.parseInt(ROW_NO);i++){ %>
<tr>
<%for(int j=0;j<Integer.parseInt(COL_NO);j++){ %>
<td>
<input type="text"name="<%=j%>_NAME_<%=i %>" id="<%=j%>_NAME_<%=i %>" onblur="fnfunction(???)">
</td>
<%}%>
</tr>
<%}%>
</table>
<%
} DB_Contact.takeDown();
%>
解释为可扩展字符串并展开.\$theDirectory\SubScript.ps1
变量的值,您应该使用调用运算符$theDirectory
。
&
你可以通过查看已解析的AST来看到:
& .\$theDirectory\SubScript.ps1 -OptionalParam $theOptionalParam -ArrayParam $theArrayParam
如您所见,如果您不使用{& .\$theDirectory\SubScript.ps1 -OptionalParam $theOptionalParam -ArrayParam $theArrayParam}.
Ast.EndBlock.Statements[0].PipelineElements[0].CommandElements[0].GetType().Name
# ExpandableStringExpressionAst
{.\$theDirectory\SubScript.ps1 -OptionalParam $theOptionalParam -ArrayParam $theArrayParam}.
Ast.EndBlock.Statements[0].PipelineElements[0].CommandElements[0].GetType().Name
# StringConstantExpressionAst
调用运算符,则&
将被解释为常量字符串,而不是可扩展字符串。