2

I want to call another powershell script with external argument. I try this but return error. anyone can help please

$direct = "D:\Learn"
Start-Process powershell.exe -WindowStyle Minimized ".\Testing.exe" -Path $direct 


Testing.exe
Param(
  [parameter(mandatory=$true)][string]$Loc
)

Get-Content $Loc\API.txt
Pause
1
  • hey SBR, let me know if the below post helps Commented Mar 4, 2020 at 8:52

3 Answers 3

2

The Start-Process cmdlet has a -AgumentList parameter:

$direct = "D:\Learn"
Start-Process powershell.exe -WindowStyle Minimized ".\Testing.exe" -ArgumentList "-Path $direct"
Sign up to request clarification or add additional context in comments.

6 Comments

it return this eror Start-Process : A positional parameter cannot be found that accepts argument '.\Testing.exe'.@Martin
Please clarify which process you want to start with which arguments
I want to start the process of Testing.exe with argument $direct
I try to change Start-Process with & the argument can work, but got problem, the main script can not continue to running before Testing.exe finish
Why you start powershell first? Just try this: Start-Process".\Testing.exe" -WindowStyle Minimized -ArgumentList "-Path $direct"
|
1

If you want to just run a File with some arguments

$filepath = ".\Testing.exe"
$direct = "D:\Learn"
Start-Process -FilePath $filepath -ArgumentList $direct -Wait -NoNewWindow

1 Comment

hi @Clint if you don't mind please check out my other question. Thank you so much stackoverflow.com/q/60598457/11076819
1

I think they all were arguments of powershell.exe. The whole argument can be wrapped in one double quote in argumentlist.

Start-Process "powershell.exe" -ArgumentList "-windowstyle minimized '.\testing.exe' -path $direct"

Or even it can be done without start-process:

& "powershell.exe -windowstyle minimized '.\testing.exe' -path $direct"

Comments

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.