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?

2 Answers 2

2

Did you try it with the -NoExit option?

powershell.exe -NoExit -command "& 'C:\A path with spaces\MyScript.ps1' -MyArguments blah"
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, it works with -noexit option. didnt know there is a -noexit option lol
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

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.