Reputation: 419
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?
Upvotes: 0
Views: 230
Reputation: 500
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'"
Upvotes: 1
Reputation: 719
Run powershell like this:
powershell -File "path\to\your\script.ps1"
Upvotes: 1