1

I'm New to powershell I want to know how to pass a variable(with Space) using commandline.

My variable is : ZCMASS LOS A

When I execute this only ZCMASS is getting printed.I want the whole variable.

Script:

powershell -command "& "C:\scripts\tivoli\mail\ZCMASS_TEST.ps1"" ZCMASS LOS A

Can anyone help me?

Windos
  • 1,796
  • 1
  • 13
  • 19

1 Answers1

0

PowerShell uses spaces as a separator in commands. Parameters containing spaces must normally be enclosed in quotation marks. An alternative to that is the back tic (`). In a case like this, where you are in quotation marks already, the back tic can come in handy.

Is this what you want?

powershell -command "& {'C:\scripts\tivoli\mail\ZCMASS_TEST.ps1' ZCMASS` LOS` A}" 

Also, if you are trying to pass this variable to a script, instead of executing as if it were typed at the command prompt, you might be looking for the -file parameter instead of -command as in this answer.

Community
  • 1
  • 1
Chava Geldzahler
  • 3,605
  • 1
  • 18
  • 32
  • Thanks a Lot. I used the back tic(`) and it worked. Below Is the script that worked: powershell -command "& "C:\scripts\tivoli\mail\ZCMASS_TEST.ps1"" `ZCMASS` LOS` A` – Shaik Shahabuddin Feb 17 '17 at 08:48