Reputation: 889
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"'"\""
Upvotes: 2
Views: 505
Reputation: 437062
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\""
Upvotes: 2