9/24/2023 0 Comments Open powershell window hereI’m definitely not an expert coder but am trying to learn more and teach myself as much as I can. I don’t have admin privileges (and won’t be able to get them) on my work PC and my goal for this is to make running these PowerShell scripts easier for my less tech-savvy teammates who need to run this process at certain times, without them calling me to help them out at 10pm on a maintenance evening. $Host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyUp”) > $nullīut each time I run it the window opens and flashes closed. I’ve tried the above with the following at the end: PowerShell -NoProfile -ExecutionPolicy Bypass -Command “& ‘PowerShellScriptPath’” SET PowerShellScriptPath=%ThisScriptsDirectory%Stage_1st_Half.ps1 The PowerShell script itself runs on my local PC but is remotely starting a process on a VM. I’ve tried a few different ways to make sure PowerShell stays open but so far it doesn’t work. bat file to run a PowerShell script that’s saved in the same folder. Hi, I realize this post is old but I had a question. Updated: JTwitter Facebook LinkedIn Previous Next Tags: Close, Console, Explorer, File Explorer, Finish, Open, PowerShell, Windows Explorer If I have missed other common registry keys or any other information, please leave a comment to let me know. From there you can just type exit and hit enter to close the window, or use the mouse to click the window’s X in the top right corner. Windows Explorer), the console window will stay open even after the script is finished executing. Now by default when you run a PowerShell script from File Explorer (i.e. reg file and click OK on the prompt to have the registry keys updated. You can copy and paste the text into a file with a. Default Value : "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') & \\\"%1\\\"\"" ps1 file and choose Run with PowerShell ( shows up depending on which Windows OS and Updates you have installed ). 1 \ Shell \ 0 \ Command Description : Key used when you right - click a. Default Value : "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "%1" Desired Value : "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "& \"%1\"" Registry Key : HKEY_CLASSES_ROOT \ Microsoft. ps1 file and choose Open With -> Windows PowerShell. exe \ shell \ open \ command Description : Key used when you right - click a. Registry Key : HKEY_CLASSES_ROOT \ Applications \ powershell. Per-script solutionĪdd a line like this to the end of your script: The other way is to launch the PowerShell process from the Run box (Windows Key + R) or command prompt using the -NoExit switch and passing in the path to the PowerShell file.įor example: PowerShell -NoExit “C:\SomeFolder\MyPowerShellScript.ps1” 2. I show how to do this a bit in this post, as the PowerShell syntax to run a script from the command-line is not straight-forward if you’ve never done it before. Open a PowerShell console and manually run the script from the command line. We have 3 solutions to fix this so that the PowerShell console stays open after the script has finished running: 1. If the script gives output that the user wants to see, or if it throws an error, the user won’t have time to read the text. When running a script by double-clicking it, or by right-clicking it and choosing Run With PowerShell or Open With Windows PowerShell, if the script completes very quickly the user will see the PowerShell console appear very briefly and then disappear. I originally included this as a small bonus section at the end of my other post about fixing the issue of not being able to run a PowerShell script whose path contains a space, but thought this deserved its own dedicated post. Keep PowerShell Console Window Open After Script Finishes Running
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |