0

Note: I need to run this script as a single line command only.

I have created a powershell script which expect 4 arguments. I tested this script from path i.e: powershell.exe c:\temp\mytest.ps1 'a' 'abc y' 'abc z' 'z'

and it works as expected. But if i call the same script:

powershell.exe C:\ProgramData\HP\HP BTO Software\bin\mytest.ps1 'a' 'abc y' 'abc z' 'z'

or

powershell.exe "C:\ProgramData\HP\HP BTO Software\bin\mytest.ps1" 'a' 'abc y' 'abc z' 'z'

it complains:

C:\ProgramData\HP\HP : The term 'C:\ProgramData\HP\HP' is not recognized as
the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:1
+ C:\ProgramData\HP\HP BTO Software\bin\instrumentation\downtime.ps1 ST ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (C:\ProgramData\HP\HP:String) []
, CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

so i tried powershell.exe 'C:\ProgramData\HP\HP BTO Software\bin\test' 'a' 'abc y' 'abc z' 'z' then it complains

At line:1 char:52
+ 'C:\ProgramData\HP\HP BTO Software\bin\mytest.ps1' 'a' 'abc y' 'abc z ...
+                                                    ~~~
Unexpected token ''a'' in expression or statement.
At line:1 char:56
+ ... C:\ProgramData\HP\HP BTO Software\bin\mytest.ps1' 'a' 'abc y' 'abc z' ...
+                                                           ~~~~~~~
Unexpected token ''abc y'' in expression or statement.
At line:1 char:64
+ ... rogramData\HP\HP BTO Software\bin\mytest.ps1' 'a' 'abc y' 'abc z' 'z'
+                                                               ~~~~~~~
Unexpected token ''abc z'' in expression or statement.
At line:1 char:72
+ ... rogramData\HP\HP BTO Software\bin\mytest.ps1' 'a' 'abc y' 'abc z' 'z'
+                                                                       ~~~
Unexpected token ''z'' in expression or statement.
+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : UnexpectedToken

Any suggestion?

2 Answers 2

1

Run powershell like this:

powershell -File "path\to\your\script.ps1"
Sign up to request clarification or add additional context in comments.

Comments

1

To expand on the first post, you will also need to wrap your parameters in double quotes as well to pass them in accordingly. Like below:

powershell.exe -file "C:\ProgramData\HP\HP BTO Software\bin\mytest.ps1" "'a' 'abc y' 'abc z' 'z'"

1 Comment

When i tried like you mentioned, powershell treat this as a single argument. $args.count result is 1.

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.