How to passing external argument by call other powershell script?

Viewed 587

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
3 Answers

The Start-Process cmdlet has a -AgumentList parameter:

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

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

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"
Related