PowerShell 中有没有办法在使用 cmd.exe 调用时将 HashTable 作为参数传递?
我想调用这样的脚本:
powershell "& 'C:\path\to\file.ps1 arg1 arg2 arg3 arg4'"
其中 arg4 是一个哈希表。这可能吗?
最佳答案
给定一个这样的脚本(foo.ps1):
param($a1, $a2, $a3, [hashtable]$a4)
"a1 is $a1"
"a2 is $a2"
"a3 is $a3"
"a4 is "
$a4
您可以从 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
关于powershell - cmd.exe powershell 哈希表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5037128/