Search code examples
powershellpowershell-2.0powershell-3.0

Double click ps1 file and powershell window disappears


I checked here and there are some topics are talking about double clikc ps1 file to run. but my situation is that I have a ps1 file opening a remote session like this:

$pw = convertto-securestring -AsPlainText -Force -String xxxxxx
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "xxxx\admin",$pw
$pc = Read-Host -Prompt "Please Enter PC name"
$session = new-pssession -computername $pc -credential $cred
Enter-PSSession $session

and i tried this way to make it double click run,

powershell.exe -command "& 'C:\A path with spaces\MyScript.ps1' -MyArguments blah"

after I entered the pc name, the console disappears....

any idea why?


Solution

  • Did you try it with the -NoExit option?

    powershell.exe -NoExit -command "& 'C:\A path with spaces\MyScript.ps1' -MyArguments blah"