Jus*_*ing 4 powershell command-line
我有以下powershell脚本:
param(
[Int32[]] $SomeInts = $null,
[String]$User = "SomeUser",
[String]$Password = "SomePassword"
)
New-Object PSObject -Property @{
Integers = $SomeInts;
Login = $User;
Password = $Password;
} | Format-List
Run Code Online (Sandbox Code Playgroud)
如果我执行,.\ParameterTest.ps1 (1..10)我得到以下内容:
Password : SomePassword
Login : SomeUser
Integers : {1, 2, 3, 4...}
Run Code Online (Sandbox Code Playgroud)
但是,如果我在像这样的单独的PowerShell实例中运行它,我就不会得到预期的结果powershell -file .\ParameterTest.ps1 (1..10).在那种情况下,我得到以下内容:
Password : 3
Login : 2
Integers : {1}
Run Code Online (Sandbox Code Playgroud)
我的问题是如何从命令行传递数组或其他复杂数据类型?
array(1..10)的各个元素作为参数传递给脚本.
另一种方法是:
powershell -command {.\test.ps1 (1..10)}
Run Code Online (Sandbox Code Playgroud)
对于同时使用powershell控制台和cmd的版本:
powershell -command "&.\test.ps1 (1..10)"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4578 次 |
| 最近记录: |