1

I need to pass a comma delimited parameter to a batch file via powershell and can't seem to get it to work. Here's how I call the batch file if I call it directly in 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. However, I must call powershell using Invoke-Command. 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?

Thanks,

-Mike

10
  • Why are you invoking powershell.exe for the sole purpose of running cmd.exe? What prevents you from running cmd.exe directly? Adding layers of indirection isn't going to help get things done. Commented Jul 7, 2014 at 17:11
  • "However, I must call powershell using Invoke-Command." Why? Commented Jul 7, 2014 at 18:36
  • I need to use powershell to pass along user credentials Commented Jul 7, 2014 at 18:41
  • I also have the same question as alroc. I think you need to explain more of your goal rather than your attempted solution. Commented Jul 7, 2014 at 20:05
  • 1
    "Our users don't have permission to execute scripts" - Do you mean that PowerShell execution policy prevents you from running scripts in PowerShell, or something else? I think you need to clarify what you want to do, not how you think it needs to be done. Commented Jul 9, 2014 at 2:28

1 Answer 1

1

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 -ScriptBlock {
     cmd /c C:\scripts\zz.cmd q,w,e
     }
Sign up to request clarification or add additional context in comments.

1 Comment

I tried powershell.exe Invoke-Command -ScriptBlock { cmd /c C:\scripts\zz.cmd q,w,e } and it failed to pass the set together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.