vs 2015 and vs 2017 powershell interactive window hangs - powershell

Installed powershell tools for visual studio, but the powershell interactive window hangs with this message:
'Please wait while the PowerShell host is initialized. This may take a few moments..."
Tried setting the ExecutionPolicy for powershell, but does not work.
The weird part is, I have visual studios installed on a personal laptop and the powershell interactive window works fine. It's my work computer that it's not working on.
Not sure if it's something to do with it being on a network, network security of some kind or what?

Related

PowerShell 5.1 in Visual Studio code behaves strangly

When using PowerShell in VS code and working interactivly, often when I highlight some code and run it then it does not print anything in the terminal. Then I simply restart The "PowerShell Integrated Console" (by pushing the trash can) and it then works again.
It is quite annoying. My ADS also acts like this. Is this a general problem with PowerShell with VS Code or is it my computer?
My VS Code version is 1.68.0. My PowerShell version is 5.1.19041.1682. And the version of the PowerShell extension is v2022.5.1

Is it possible to run code in Visual Studio Code without a shell?

My school has blocked cmd and Powershell due to security concerns. Unfortunately for me, this prevents VSC from running code! I love using VSC, so I'm wondering if there's any way I can continue to use it without the powershell or cmd terminals.

Did Windows 11 break Visual Studio Code

I 'upgraded' my Win10 system to Win11. Since then Visual Studio Code simply will not run my PowerShell scripts. What happens is the little 'Pause/Step-x/Restart/Stop' ribbon appears at the top. All I can do then is hit the Stop. I uninstalled & re-installed VS-Code to no avail. I deleted the .vscode folder in my user-profile, again to no avail.
I have both PowerShell 5.1.22000.65 Desktop and 7.1.3 Core installed on this system. VS Code is 1.58.2 (system setup). PowerShell extension is v2021.6.2.
The same scripts run happily in Windows Terminal, PowerShell command window and the ISE.
Any ideas please?
Thanks very much.
Update 13th August 2021: PowerShell scripts are now running as expected in Visual Studio Code.
VS Code is 1.59.0.
PowerShell Extension is 2021.8.0.
The most likely change to have enabled scripts to work again is the update to PowerShell 7.1.4 Core (was 7.1.3).

Can I detect in Powershell that I am running in VS Code's integrated terminal?

I would like to modify the standard PowerShell profile in Windows if the Powershell opens inside VS Code integrated terminal (when you are editing e.g. python scripts in VS Code, rather than PS scripts, which opens the ISE profile in any case).
Is there some environmental variable that gets set by the integrated PowerShell? Or is there some way of opening Powershell with a particular profile, instead of the default?
Thanks
VS Code creates an environment variable named TERM_PROGRAM. You can check it for a value of vscode, something like this:
if($env:TERM_PROGRAM -eq 'vscode') {
# do some stuff...
}
If you want to check if you're running within PowerShell Integrated Console (ships with PowerShell extension) under vscode and not just any powershell console running under vscode, you can:
if ($Host.Name -eq 'Visual Studio Code Host') {
Write-Output 'PowerShell Integrated Console'
}
This is meaningful to detect because it is the only powershell console host that provided full debugger support (eg. break on exception experience) and debugger integration with vscode.
You said you're into modifying profile when running within vscode, then you should check (again with PowerShell integrated console which ships with PoweShell extension):
PS> $PROFILE.CurrentUserCurrentHost
C:\Users\username\Documents\PowerShell\Microsoft.VSCode_profile.ps1
PS> $PROFILE.AllUsersCurrentHost
C:\Program Files\PowerShell\7\Microsoft.VSCode_profile.ps1
If people are working on PowerShell code within Visual Studio Code, then why they would NOT install PowerShell extension which ships with a specific console that fully integrates with Visual Studio code and on the top of that, provides you a profile file specifically geared towards Visual Studio code?

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.