如何将参数数组传递给 Powershell 命令行 [英] How to pass array of arguments to Powershell commandline

查看:97
本文介绍了如何将参数数组传递给 Powershell 命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将参数数组传递给 powershell 脚本文件.

I am trying to pass array of arguments to powershell script file.

我试图在命令行中像这样传递命令行.

I was trying to pass the commandline like this in command line.

Powershell -file "InvokeBuildscript.ps1" "z:\"组件1"、组件2"

Powershell -file "InvokeBuildscript.ps1" "z:\" "Component1","component2"

但它似乎并没有采用参数.我错过了什么?如何传递参数数组?

But it doesn't take the parameters it seems. What am i missing? how to pass array of arguments?

推荐答案

简短回答:更多的双引号可以帮助...

Short answer: More double quotes could help...

假设脚本是test.ps1"

suppose the script is "test.ps1"

param(

    [Parameter(Mandatory=$False)]
    [string[]] $input_values=@()

)
$PSBoundParameters

假设想传递数组@(123,"abc","x,y,z")

Suppose would like to pass the array @(123,"abc","x,y,z")

在 Powershell 控制台下,将多个值作为数组传递

Under Powershell console, to pass multiple values as an array

.\test.ps1 -input_values 123,abc,"x,y,z"

在 Windows 命令提示符控制台或 Windows 任务计划程序下;一个双引号被 3 个双引号代替

Under Windows Command Prompt Console or for Windows Task Scheduler; A double-quote are replaced by 3 double-quotes

powershell.exe -Command .\test.ps1 -input_values 123,abc,"""x,y,z"""

希望对大家有所帮助

这篇关于如何将参数数组传递给 Powershell 命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆