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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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`

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.