2

I have the following .BAT script that basically calls Powershell and it works fine.

CMD /C PowerShell "SL -PSPath '%CD%'; $Path = (GL).Path; SL ~; Start PowerShell -Verb RunAs -Args \"-ExecutionPolicy ByPass" SL -PSPath '"$Path"'; & '".\RDPSwitchToConsle.ps1"'"\""

I'm trying to extend it to add more arguments, specifically -WindowStyle Hidden.

I've tried a couple of things, but can't get the script .BAT to run. It just opens Powershell straight away and closes immediately, which is a sign that the arguments/parameters are not loaded correctly due to incorrect structure.

I've tried adding the argument like this:

CMD /C PowerShell "SL -PSPath '%CD%'; $Path = (GL).Path; SL ~; Start PowerShell -Verb RunAs -Args \"-ExecutionPolicy ByPass -WindowStyle Hidden" SL -PSPath '"$Path"'; & '".\RDPSwitchToConsle.ps1"'"\""

1 Answer 1

2

Apply -WindowStyle Hidden to the Start-Process (start) call, not to the nested powershell.exe call.

Here's a simplified version of your command:

PowerShell "SL ~; Start -WindowStyle Hidden -Verb RunAs PowerShell \"-ExecutionPolicy ByPass SL -PSPath '%CD%'; ^& .\RDPSwitchToConsle.ps1\""
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.