0

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?

Community
  • 1
  • 1
Root Loop
  • 3,004
  • 9
  • 46
  • 72

2 Answers2

2

Did you try it with the -NoExit option?

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

This page provides a batch script (and additional info) making the process quite easy for having this no-exit behavior (and a fix for when the path has spaces) when launching from Windows Explorer: http://blog.danskingdom.com/fix-problem-where-windows-powershell-cannot-run-script-whose-path-contains-spaces

Venryx
  • 15,624
  • 10
  • 70
  • 96