Problems using start-process to call other powershell file

batch-file, powershell

Solution

You should be using `Start-Process powershell.exe`, and passing the path to the script as the `-File` argument in your arg list. The `No application...` bit means that you don't have a default application set to work with .ps1 files on your machine. If you do the whole `Right Click -> Open With -> Select Application -> check "Use this program as default..."` tidbit on any .ps1 file, then the message goes away. My default program is notepad, so when I use `Start-Process` on a .ps1, it pops it up in that.

Edit:

To put it all together...

Start-Process powershell.exe -ArgumentList "-file C:\MyScript.ps1", "Arg1", "Arg2"

Or, if you define `$powershellArguments` as Keith says (`$powershellArguments = "-file C:\MyScript.ps1", "arg1", "arg2", "arg3", "arg4"`), then like this:

Start-Process powershell.exe -ArgumentList $powershellArguments

Problem

EDIT::::See very bottom for current state of issue. In the current set up, a batch file calls a powershell script with the following ``` powershell D:\path\powershellScript.v32.ps1 arg1 arg2 arg3 arg4 ``` I would like to convert this into a powershell script calling another powershell. However, I'm having issues using start process. This is what I currently have but upon execute I get the following ``` No application is associated with the specified file for this operation ``` This is the powershell that is executing ``` $powershellDeployment = "D:\path\powershellScript.v32.ps1" $powershellArguments = "arg1 arg2 arg3 arg4" Start-Process $powershellDeployment -ArgumentList $powershellArguements -verb runas -Wait ``` EDIT:::::: Due to the help below, I now have the following ``` $username = "DOMAIN\username" $passwordPlainText = "password" $password = ConvertTo-SecureString "$passwordPlainText" -asplaintext -force $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username,$password $powershellArguments = "D:\path\deploy.code.ps1", "arg1", "arg2", "arg3", "arg4" Start-Process "powershell.exe" -credential $cred -ArgumentList $powershellArguments ``` However, when I execute this script from a remote machine I get "access denied" errors, even though the username used has full administrator access to the machine

Original source