powershell - cmd.exe powershell 哈希表

标签 powershell cmd

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/

相关文章:

linux - 批处理文件转换为 Linux 脚本

javascript - 在生产中运行平均堆栈应用程序

powershell - 使用 Powershell 在远程 session 上强制执行版本 2 以进行 SharePoint 管理

Azure 的 New-AzureRmHDInsightCluster 命令不接受记录的 ComponentVersion 选项

powershell - Azure:构建模板:如何提取默认存储帐户

powershell - 如何在powershell中遵循快捷方式

powershell - 标准输入到 powershell 脚本

windows - 使用批处理脚本自动将最新文件复制到文件夹

windows - 通过cmd在ftp连接中使用变量

cmd - abbyy Finereader.exe 寻找 cmd 命令以在其他程序中使用