PowerShell window launches then closes immediately - powershell

When I start PowerShell, it launches and the the window it opens in closes immediately.
I tried taking a screenshot and it says there's a registry error:
Reading the value of registry key
SOFTWARE\Microsoft\PowerShell\3\PowerShellEngi ne\PowerShellVersion
causes the following Win32 error: The system cannot find the file
specified.
Why is this happening?
I'm running Windows 8.1.

If anyone else is having this issue...
I tried everything on this forum as well as Microsoft's.
Ended up being an issue with my ISE profile loading $moduleBrowser that kept crashing ISE after startup [Microsoft.PowerShellISE_profile.ps1].
Try launching ISE with no profile using powershell_ise.exe -noprofile. Then, open your PowerShellISE_profile.ps1. Comment it out, save it, close ISE.
Then try re-opening ISE, load your "commented-out" PowerShellISE_profile.ps1, step through your profile to see what is causing the failure.

In my case, it was just closing in like a second after starting and I wasn't seeing any errors.
Start command prompt as Administrator
run sfc /scannow
That fixed it for me.
I found it here - there were few more suggestions
https://www.youtube.com/watch?v=40j4Mxt24PY

i just fixed the problem by adding the registery keys manually

Related

Why PowerShell opens a new window when running exe

I have a PowerShell script like this:
$tfExe = path/to/tf.exe
& $tfExt ... do something
On my computer (and other PCs) if I run this script I get the .exe output in my PowerShell window.
When I run the script on another computer (with Windows 7 32-bit) it opens a cmd window, the output displayed there, and the window is immediately closed.
The issue occurs for each .exe tool, even in robocopy.
Why does this happen and how can I change it?
I had another issue with my PowerShell and the solution to that issue also solved this issue.
In my PATHEXT environment variable I didn't have .exe. When I added it, the issue solved and all the .exe tools ran smoothly and the output appears in the PowerShell window.
I had a similar issue and figured out I had deleted the folder I was executing the commands from.
PATHEXT was ok:
But this was not (I had deleted it outside of PowerShell - oops):
Navigating to another path solved the issue.
You are starting an external exe, so it's working as intended. You could however try using cmd.exe /K - more info here https://ss64.com/nt/cmd.html

Whenever I open integrated terminal in VS code 1.18, it crashes PowerShell

Even though I have set below code in setting.json:
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
Whenever I open the "integrated terminal" it starts and right away shows:
"The terminal process terminated with exit code: 259"
There is also a dialog outside code saying:
"powershell has stopped working
A problem caused the program to stop working correctly.
Windows will close the program and notify you if a solution is available."
this happens in 32bit and 64bit too
Any idea how to overcome this?
The code 259 usually means STILL_ACTIVE and this is rather strange.
You may try to use ProcessMonitor to determine which processes are started during your call and perhaps that gives you a clue.
Open Task Manager
I Clicked on End Task on all process of VS Code
Error vanished

VSCode Powershell integrated terminal hangs when starting

I am using VSCode version 1.12.2 in Windows 10 x64 build 16193. I am trying to debug Powershell in VSCode, but I cannot get the PowerShell Integrated Terminal working. Every time I started the terminal, here's what I see:
And then it hangs in that stage. I can still debug, start, step in, step out..., but I cannot view my variable or run any expression.
My VSCode is using powershell x64 here:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
So this is a known issue with this version of windows 10. Workaround here: https://github.com/PowerShell/vscode-powershell/issues/742
It's possible it's getting stuck on something while loading your profile(s). Try adding this to your settings to skip this:
"powershell.enableProfileLoading": false
I have had a similar problem, it seems. I cannot be sure it is the same, but when I would "load a file with VSCode" (user installer confirmed, system installer unconfirmed), it would hang. The following avenues tested:
Double-clicking on a PS1 file (the association to Code being made)
Starting VsCode empty and then loading the file
Starting VsCode from the command-line with a file-designation parameter
Using the --verbose switch, I got a listing which lead me to believe that VsCode seemed to be checking on updates using NPM (I could be wrong here).
Whatever the underlying problem, I did a lot of prodding and probing, and the cure I found was this.
Delete the directory called C:\Users\YourUserId\.vscode.
This directory is rather large, is not wiped by software removal, and may be corrupted apparently. After deleting it, the problem disappeared.

Why is my command prompt freezing on Windows 10?

I'm adding this question after spending an entire day wrestling with this incredibly frustrating feature of the Windows 10 command prompt which made me think there was something wrong with my console application code. I hope it will help someone.
Issue: My console application seems to randomly stop running. What is going on?
The issue ended up being a new feature of the windows 10 console. Under the default config, whenever you click on a command window in windows 10, it immediately halts the application process when it attempts to write to the console. When this happens, the command window has gone into "selection" mode.
You can tell it has happened because it will prefix the title bar of the command window with the word "Select" :
To get your program running again, you have to press escape or click somewhere else.
To get rid of this strange behavior, you can disable QuickEdit mode:
What I'd like to add here to Shaun Rowan's answer is that for it to work in all console windows you have to click "Defaults", instead of "Properties" and make your changes there, as described in this post.
I faced this problem very recently where one of the users (who had Quickedit configured on his Command Prompt) was using a tool I developed in Java, and was getting the tool frozen while running it from command prompt.
Finally what solved the problem was to redirect the logging inside the batch script to a file as shown below:
#echo off
...
java.exe -jar mytool.jar
needed to be updated to
java.exe -jar mytool.jar > log.txt

Why won't PowerShell ISE let me set breakpoints when running as Administrator?

Having failed to get PowerGUI to work properly I've fallen back on PowerShell ISE. However if I run this as Administrator it won't let me set any breakpoints.
If I launch as normal (my login is a member of Administrators) all is well but because I need to script some tasks that require full administrator rights this is no good.
I have saved the script as a proper file (i.e. it's not "untitled1.ps1") but no joy.
I'm running Windows 7 x64 Ultimate.
Strangely this doesn't seem to be a problem on my Windows 2008 R2 dev box (I'm logging in as user that is a member of Administrators then running PS ISE "As Administrator" and breakpoints are set and hit.
Any ideas why this would be?
I also faced the same issue, saving the file to a physical location enabled all debugging capabilities.
It looks like there's a problem with PowerShell and square brackets in folder and filenames.
Both PowerGUI and PowerShell ISE won't hit breakpoint if the script being debugged resides in a folder with [ or ] in the name.
I notice you're running x64. Is there any chance that you're running x64 ISE but have only set the execution policy away from restricted on x86 (or vice-versa).
I am using Visual Studio Code and in my case, I was missing the powershell extension.
Was facing the same issue because I had used other editor to make changes to the ps1 file. After opening the file with PowerShell ISE and clicking "Save" solved the issue for me.