Windows 如何将参数传递给powershell命令行
如果有人帮我完成这项小任务,我将不胜感激。我想将命令行参数传递给powershell脚本(该脚本不是文件) 假设,我只想传递messagebox将显示的参数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.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完成@马蒂亚斯·杰森坦克斯