简体   繁体   English

Invoke-Command Powershell参数问题

[英]Invoke-Command Powershell parameter issue

I need to pass a comma delimited parameter to a batch file via powershell and can't seem to get it to work. 我需要通过Powershell将逗号分隔的参数传递给批处理文件,并且似乎无法使其正常工作。 Here's how I call the batch file if I call it directly in powershell: 如果直接在Powershell中调用批处理文件,则这是如何调用它:

PS C:\Users\Mike> type zz.cmd
@echo off
echo/* = [%*}
echo/1 = [%1]
echo/2 = [%2]
echo/3 = [%3]
pause
PS C:\Users\Mike> cmd /c zz "q,w,e"
* = [q,w,e}
1 = [q]
2 = [w]
3 = [e]
Press any key to continue . . .

If I use cmd /c zz """q,w,e""" or cmd /c zz '"q,w,e"' I will get "q,w,e" for arg 1. This is good. 如果我使用cmd / c zz“”“ q,w,e”“”或cmd / c zz'“ q,w,e”'我将为参数1获得“ q,w,e”。这很好。 However, I must call powershell using Invoke-Command. 但是,我必须使用Invoke-Command调用powershell。 When doing this, the script doesn't work: 这样做时,脚本不起作用:

powershell.exe Invoke-Command -ScriptBlock { "cmd /c E:\\npoess\\oo\\WoD\\zzz" '"q,w,e"'}

Any idea how to get the powershell call from the command prompt to get "q,w,e" as one parameter to the batch file? 知道如何从命令提示符处获取powershell调用以将“ q,w,e”作为批处理文件的一个参数吗?

Thanks, 谢谢,

-Mike -麦克风

this invoke-command without all the quotes works for passing a for me : I think that the quotes around the variables passes the set as a string instead of separate values. 这个没有所有引号的invoke-command可以为我传递a:我认为变量周围的引号将集合作为字符串而不是单独的值传递。

Invoke-Command -ScriptBlock {
     cmd /c C:\scripts\zz.cmd q,w,e
     }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM