Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 如何将参数传递给powershell命令行_Windows_Powershell_Arguments - Fatal编程技术网

Windows 如何将参数传递给powershell命令行

Windows 如何将参数传递给powershell命令行,windows,powershell,arguments,Windows,Powershell,Arguments,如果有人帮我完成这项小任务,我将不胜感激。我想将命令行参数传递给powershell脚本(该脚本不是文件) 假设,我只想传递messagebox将显示的参数 powershell.exe -command "$str=$args[0];[System.Reflection.Assembly]:: LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.Messagebox]::Show($str);" 'foo'

如果有人帮我完成这项小任务,我将不胜感激。我想将命令行参数传递给powershell脚本(该脚本不是文件)

假设,我只想传递messagebox将显示的参数

powershell.exe -command  "$str=$args[0];[System.Reflection.Assembly]::
LoadWithPartialName('System.Windows.Forms');
[System.Windows.Forms.Messagebox]::Show($str);" 'foo'

我希望foo显示在messagebox中。我得到一个空的信息箱。也许我错过了一些小东西

将整个内容包装在scriptblock
{}
中,并使用调用操作符
&
使用参数调用它:

powershell.exe -command "& {$str=$args[0];[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');[System.Windows.Forms.Messagebox]::Show($str)} 'foo'"

不要使用
-command“code”arg
,而是使用
-command“&{code}arg”
谢谢Mathias,它可以工作@杰森请写下你的评论作为答案,这样就不会有人浪费时间了。@JPBlanc完成@马蒂亚斯·杰森坦克斯