[英]cmd.exe powershell HashTable
Is there a way in PowerShell to pass a HashTable as an argument when being invoked with cmd.exe? 在使用cmd.exe调用时,PowerShell中是否有一种方法可以将HashTable作为参数传递?
I want to invoke a script like this: 我想调用这样的脚本:
powershell "& 'C:\path\to\file.ps1 arg1 arg2 arg3 arg4'"
Where arg4 is a HashTable. 其中arg4是HashTable。 Is this possible?
这可能吗?
Given a script (foo.ps1) like this: 给出一个像这样的脚本(foo.ps1):
param($a1, $a2, $a3, [hashtable]$a4)
"a1 is $a1"
"a2 is $a2"
"a3 is $a3"
"a4 is "
$a4
You can invoke it from cmd.exe like so specifying a hashtable as the fourth parameter: 您可以从cmd.exe调用它,如此指定哈希表作为第四个参数:
C:\> powershell -command "& {c:\foo.ps1 1 2 three @{name='John';age=45}}"
a1 is 1
a2 is 2
a3 is three
a4 is
Name Value
---- -----
name John
age 45
唯一想到的是将哈希表保存为xml,并将其传递给文件名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.