r/PowerShell • u/Mc_Humphrey • Oct 31 '21
Who uses Visual Studio Code for PowerShell Scripting?
I personally do, but only for typing scripts. I then copy code into ISE and run it on Sandbox environments.
What does everyone else do? What settings do you use if you use VS Code?
24
u/datlock Oct 31 '21
I don't do extremely complicated scripting, but I've since switched to Code for both writing and running scripts. I appreciate the integration with git, and the fact that I can more easily work in other languages as well (mostly shell, json, xml).
Also have a specific 'blame' extension that allows me to see per-line who the author was and directly see the relevant commit/pull request. Useful if you're not the only author or are integrating with something someone else wrote.
10
u/dathar Oct 31 '21
There are a couple of extensions that I love: rainbow csv and rainbow indent. Colors all the things! Makes it easier to read things in general.
1
10
u/JiveWithIt Oct 31 '21
I have done all of my PowerShell programming in VSCode since it first got support for it. Only plugin I use is the theme Flatland Monokai
It has great support for Pester
10
u/32178932123 Oct 31 '21
I use VSC - There was a while where I had an issue with Powershell refusing to load in VSC but that seems to be a lot more stable now. I think ISE is one of those programs that if you grew up with you're fine with but as I started straight with VSC I struggle with ISE when I have to troubleshoot something server-side.
For example, the other day I had to debug something in ISE and the step in/over options are hidden in a sub menu, I also found hovering over a variable to get the value was intermittent. Sometimes it might quickly flash and other times not appear at all. I prefer the way VSC has all the variables down the side during a debug session so you can expand them yourselves. I also seem to recall the intellisense doesn't have autocomplete for common things like foreach loops, functions etc which VSC does.
I don't really have any special settings for VSCode, I use the built in Sync and the following extensions:
Powershell (obviously!)
Git History (helpful to see a visual idea of your git repository)
Todo Tree (you can type
#TODO: Notes hereand it'll put it in your Todo Tree list so you can go back to things)Rainbow Brackets (colour codes brackets for easier reading)
Indent Rainbow (makes a tab indent shaded for easier tracking).
1
u/Vzylexy Oct 31 '21
I ran into that crap before as well, don't remember what I did to fix it, but I'm really glad I did.
7
u/Emiroda Oct 31 '21
It's the Microsoft recommended way of writing PowerShell code, take from it what you want.
I use VSCode - debugging and extensions are the main reasons why.
Intellisense is still a bit buggy, not too happy about that, but I haven't fired up ISE in over 3 years despite that.
5
u/Pacers31Colts18 Oct 31 '21
Yeah, only code for me. Once you get it setup with the right plugins there is no going back.
4
u/parkthrowaway99 Oct 31 '21
the ability to see all variables, have them organized in local, script, global, etc, and hover over them to see values, specially with object type variables made me switch permanently..
2
1
u/jr49 Oct 31 '21
Iāve been moving to VSC, maybe 80% of my scripting now. I have yet to see these features. Gonna have to do some reading tonight.
4
3
Oct 31 '21
I use VSCode for Powershell almost exclusively. Once you turn off snippets it handles intellisense like a dream. GIT access in the console is a lifesaver for our usage. Also, the PSScriptAnalyzer and one click fomatting has saved me a bunch of time and encourages best practices in scripts.
3
u/Tidder802b Oct 31 '21
I use VSC exclusively. The only frustration I have is sometimes I can't run a script to debug it and have to kill the powershell console session and re-run. It usually happens when I'm continuously making changes and running a script to figure something out.
3
6
u/Whipitreelgud Oct 31 '21
I like the idea of VSC, but find ISE with ISESteroids to be far more productive.
4
u/verschee Oct 31 '21
I tried using this but continually got run errors and crashes. Might give it another shot because VSCode is becoming less cumbersome.
1
2
u/cheffromspace Oct 31 '21 edited Oct 31 '21
I moved to NeoVim with LunarVim as the IDE layer with the PowerShell language server for intellisense and diagnostics. Best editor Iāve ever used by far. The learning curve is pretty steep but Iām a developer and I only use PS for scripting some common tasks and testing APIs; itās been more than worth it.
1
u/jantari Oct 31 '21
I also use neovim but could never get the PowerShell LSP working with it - do you have any guides or something you followed?
1
u/cheffromspace Oct 31 '21 edited Oct 31 '21
Trial and error mostly. One thing that tripped me up is the bundle_path setting only seems to work if you download the zip and not if you clone the repo & build locally.
Also I noticed PowerShell has been added to the lsp installer plug-in (think itās this one but Iām on my phone so Iām not certain https://github.com/williamboman/nvim-lsp-installer/). I believe the installer only works for Windows.
Iād be happy to create a guide or video if thereās interest.
3
u/jantari Nov 01 '21
Thanks for that, LSP-installer didn't support it last time I had checked. I tried again yesterday and now it was super easy, the lap itself works now I just need to get completion and some of its features set up
2
2
2
2
u/nodiaque Oct 31 '21
I use sapien PowerShell studio. Love it and it can also compile. It have a lot of built in code, routine and make creating Gui so much easy
2
u/darkrhyes Nov 01 '21
It took a bit but i have almost completely switched to vscode. Still use ISE when i need to run a setup script on a new server.
2
u/FahidShaheen Nov 01 '21
Build in code. Test in ISE.
Mainly as I need to test on various production machines to simulate the actual results of running the script... can't really be going around installing VS Code on random production machines.
Also leveraging ISE with Enter-PSSession... noice!
The Intellisense is better in that my machine has various drives and software installed on D, etc. Whereas ISE Intellisense on production machines brings up results that are relevant.
But clearly, clearly there is no matching the power VS Code, it is the bee's knees.
5
u/geek73 Oct 31 '21
I use ISE on my servers because it is there. And Code isnāt. This is where I develop and test scripts prior to deploying. I use Code on my box that Iāve copied the script to in order to use GIT and do a pull request into the repo. I prefer Code but not enough to have it running on production or lab servers since security freaks out whenever they detect anything new. Plus we reimagine a lot so Iād constantly be reinstalling it.
1
u/ecco7815 Nov 01 '21
Same here. VSCode with the powershell extension got blocked for me on my dev server and I had to move back to ISE. While I prefer VSCode, Iām forced to use ISE.
2
u/jimmystead Nov 01 '21
There is a portable version of vscode. Nothing to install so you should be able to just copy it out there.
1
u/buffychrome Nov 01 '21
He might be referring to the exe itself being blocked by a security agent like Bit9/CarbonBlack.
1
u/ecco7815 Nov 01 '21
Correct. I can install VSCode, but when it tries to load the ps module/extension, it gets blocked.
1
u/buffychrome Nov 01 '21
Yeah, I have the same issue with a couple of extensions like the Powershell Universal Pro tools extension because it uses its own version of powershell.exe under the hood. Doesnāt match the hash of the actual PS executable so it gets blocked.
0
Oct 31 '21
[deleted]
0
u/geek73 Nov 01 '21
Most of what I write are custom performance counters, custom monitors that drop alerts into our ticketing system, automation, and updates to our DSC. This is Elmore easily done directly in a server in the environment for testing before I deploy it to the whole fleet.
3
Oct 31 '21
Iāll use it in a pinch, but Iāll also use Notepad++ . My go to is poweshell Studio by Sapien.
1
u/Hoggs Nov 01 '21
I used to use NP++ for quick edits, and reserve VSC for actual script work.
That was until I realized that VSC actually starts up faster than NP++, even when loaded up with extensions.
Weird, but w/e. I use VSC for pretty much everything now.
3
u/BlackV Oct 31 '21 edited Oct 31 '21
Me, but powershell is a 2nd class citizen on vscode, ISE works better for a bunch of things (autocomplete, snipits, and some others)
but its light weight, its fast (errors aside), its search functions are amazing and git support (which i guess technically isnt code its just git underneath) is great
I switch between bot constantly depending on what I'm doing, also ISE is default on every windows server I touch code is not (only on my management servers and RDS servers)
Laptop I use
code insiders
powershell preview plugin
git lens plugin
XML Toos
Markdown lint
Workstation
code
powershell plugin
git lens plugin
XML Toos
Markdown lint
Inline Values support for powershell (enables in-line values on variables when debugging powershell)
manage Servers
VSCode
Powershell plugin
git lens
Worspace has specific settings (allerman coding and trim white space and so on) so the team formats consistantly then some user defined settings for the things I like (kept to a minumum)
EDIT: Bah formatting
2
u/Thotaz Oct 31 '21
I use VS code to handle my project files and making minor edits to the code. I use ISE to write/test the code. I do this because I don't think the script writing experience in VS code is up to par with ISE, issues off the top of my head include:
Inaccurate syntax highlighting
Code ran with F8 is added to the history
Confusing multi cursors instead of the more traditional column selection with virtual space
Linebreaks aren't shown in the tooltip window so it's hard to use .NET methods because the overloads aren't shown properly.
1
u/SpacezCowboy Nov 01 '21
I use United Ubuntu Linux theme. It's the best I've found for good syntax highlighting in vscode.
1
u/Thotaz Nov 01 '21
It doesn't matter what theme you use, it's the underlying textmate grammar that is inaccurate.
0
Oct 31 '21
[deleted]
1
u/Thotaz Oct 31 '21
Keys in hashtables use the variable scope. Commands that don't use the verb-noun structure (or use an unapproved verb) have no scope. The Where/ForEach collection methods are marked as keywords. Parameters and parameter values also have no scope. I'm sure there's more that I can't think of right now. This is just with simple and valid syntax, if you throw in obfuscated or wrong syntax it probably won't account for that either.
Enabling semantic highlighting fixes this somewhat as it now uses the actual PowerShell tokens instead of fancy regex, but they never finished implementing it and what they did implement wasn't accurately mapped, hence them disabling it by default for now.
There is a PR that mostly solves the inaccuracies here: https://github.com/PowerShell/EditorSyntax/pull/156 but it has been WIP since 2019 with no sign of him finishing it in the near future. I don't blame him because it's a ton of work and semantic highlighting sort of made it irrelevant but it does leave us without an official editor that can handle the PS6+ syntax.
IMO they should push the VS team harder about letting them open source the components used to build ISE. Lots of people want it and I can't imagine it would take a lot of work to maintain the ISE considering that it already supports PS6+ through PS remoting.
2
u/razzledazzled Oct 31 '21
Ise is honestly garbage. Vs code is an actual ide and has really robust features without being slow as fuck on startup
1
u/Trakeen Oct 31 '21
Vs code, i deploy powershell code as azure functions. Not sure you can do that easily with any other tooling and it supports all the other languages i use. Json extension is pretty handy though it does choke on some huge files. Even use it for gcode
C# i still use full visual studio for
1
u/JeremyLC Oct 31 '21
I love it, BUT... there's been some kind of problem with the PoSH plugin for awhile now. If my code has a typo or syntax error anywhere, I don't get an error when I try to run it. Instead it just hangs, then segfaults when I ctrl-c to break. I've had to paste entire scripts into ISE to see what's wrong when my fat fingers managed to make very subtle typos.
1
1
u/scattersquirrel Oct 31 '21
I like to leverage the intellisense. Great for creating advanced functions. And git, although, you can use git from ISE too. I feel like the code is easier to read in vs code. But thatās my personal opinion.
1
u/iceph03nix Oct 31 '21
I use code for the whole process, aside from windows terminal for actually running stuff.
No particular extra settings, just the basic PowerShell addin, and a couple qol add INS like a bracket Colorizer.
1
u/throwawayacc90s Oct 31 '21
I still use ISE when I want to cobble up a quick script but VS Code for everything else.
1
u/Revolutionary-Gold53 Oct 31 '21
Iām between VSCode and PowerShell Studio. I just recently started with PSStudio and am not sure which I prefer, except for PSStudio for GUI development.
1
u/major_winters_506 Oct 31 '21
Iāve switched to code with the PowerShell extension. I also do a lot of Ansible scripting and having both in one is amazing.
1
1
1
1
1
u/admoseley Nov 01 '21
I use VSC and ISE. I still dont like the behavior of running my scripts vs how they behave in ISE, but I love the VSC Script formatting and integration with github. I think ultimately I'll be using VSC exclusively but it's just taking time.
1
u/enforce1 Nov 01 '21
I use VSCode for anything substantial. I am super guilty of opening ISE to knock something together quick and then itās a couple hundred lines and oops
1
u/halr9000 Nov 01 '21
Itās great! Been a huge fan since we interviewed the author of the plug-in way back. Canāt for the life of me remember which episode though. :)
1
1
u/monahancj Nov 01 '21
Sapien PowerShell Studio to edit and a PowerShell console window to run the scripts while testing.
I only use the ISE when I'm on a system without PowerShell Studio and the script is short.
If my company wasn't paying for PowerShell Studio I'd use VS Code.
1
u/joshooaj Nov 01 '21
I work with hundreds of files including markdown documentation for my module. Doing this in ISE is totally impractical.
The PowerShell extension's intellisense has been a disappointment but the team has been making it better and are effectively doing a rewrite if I understand correctly. Really that's my only gripe compared to ISE.
The ISE intellisense is solid. But ISE lacks snippets, formatters, linting for other document types, usable management of large project directories.
For short, experimental or standalone snippets I often use ISE. For a project with no more than a few files, you're not missing out on much by sticking with that. VSCode isn't offering much to you in exchange for the degraded intellisense experience. When you're working with dozens of files or more, and multiple file types, the benefits of an extensible polyglot editor like VSCode shine through and make up for a bit of the usability barriers you eventually learn to cope with.
1
1
u/RoTalk Nov 01 '21
I miss PowerShell Studio... Killer GUI Designer plus you can even add your own SSL to your output project.
1
u/gricey91 Nov 14 '21
I use VS Code for Powershell scripting. One further I also use code-server (web-based VS Code) and powershell on my remote linux boxes for a lot of my cron jobs and server-side functions. I know how to code bash scripts, python, node etc etc..., just Powershell is so damn convenient for knocking together both simple and complex shell scripts.
1
u/assafstone Nov 20 '21
VS Code is the only way to fly. Havenāt cracked open the ISE in years.
For every significant (i.e. multi-module) powershell app I build I set up the sandbox so debug runs it the way I want, and test runs my Pester modules.
1
u/xShawn117x Nov 23 '21
So...I've been in IT for 20 years and I've barely ever touched PowerShell. Can someone explain to me what the difference between PowerShell, ISE, and Visual Studio Code? I've always been a CMD scripter and dabbed in VBS.
1
1
u/Metalearther Oct 31 '21
I do for the initial coding. It is great for assisting with syntax, but when testing as 99% of what I run needs to be ran with admin creds on a domain controller I use ISE for the actual testing. Love What if...
1
u/Emiroda Oct 31 '21
but when testing as 99% of what I run needs to be ran with admin creds on a domain controller
You're RDPing to your domain controllers?
0
u/Metalearther Oct 31 '21
No. To a jumpbox that allows me to run with admin creds. We never touch the DC unless necessary.
0
Nov 01 '21
[deleted]
1
u/Metalearther Nov 01 '21
If you know what you are doing and use What if you can run all sorts of stuff on a DC. If it is something major, like making changes, that does not get done on a DC until finalized in a sandbox environment.
1
Oct 31 '21
I use gVim with some syntax color profile I found. That and Microsoft's online documentation.
1
u/BigHandLittleSlap Nov 01 '21
I only use it because I'm forced to. The most basic things are unreliable and broken, especially tab-complete.
When tab-completing a parameter name like when pressing tab at this point in a line:
Get-Item -It will "helpfully" show about 5 pages of snippets like "do-while" and "ex-DSC resource provider (class-based)". Much of the time it'll scroll past the actual parameter names to the first such snippet, hiding the real list that you wanted.
Those snippets it is suggesting aren't valid in the given context. It's like I'm asking for driving directions, and it is answering "red".
Similarly, if you're just typing "space" after a completed parameter name, it'll pop up any alternatives with a little box with 1/2 of the available options in it. Cool, cool, cool. Except that that this only has the correct layout if the command is in the bottom 80% of the screen. On the first few lines it'll be a pop-under below the tab-complete flyover and will be hidden from view.
How did this pass the most basic QA -- even just the developer himself testing his own code -- I will never know. Whomever wrote this probably never used PowerShell themselves, like... ever. Just tasked with banging out the tab-complete code.
"Job done boss!"
3
u/MadBoyEvo Nov 01 '21
Did you report your findings? Try the new preview extension and provide feedback. It uses rewritten system that's supposed to work correctly. It still has bugs but they were rewriting it for 1 year due to the architectural problems you describe.
2
u/BigHandLittleSlap Nov 01 '21
These are "features" working as intended. Take a look at the file that turns up if you search for that DSC snippet: https://github.com/PowerShell/vscode-powershell/blob/master/snippets/PowerShell.json
16 contributors.
I bet none of them feel responsible for the overall usability of VS Code. That's someone else's problem. They're just here to add more snippets...
Why would I spend my time contributing to VS Code, providing free labour to the world's biggest company by market cap (recently dethroning Apple)?
I charge $100 per hour. To Microsoft, I charge $500 per hour.
You tell me where I can send my bill, I'll start contributing to VS Code's user interface quality.
3
u/MadBoyEvo Nov 01 '21
Why not disable snippets? If something doesn't work the way I want to - I disable it.
Also - did you open an issue describing the problem you're having with snippets? Or maybe there is already open one?
What I am trying to say it's easy to complain on Reddit, but if we don't fill bugs - it won't get fixed. Everyone complained on intellisense and autocomplete and now in preview there's new version - that hopefully fixes it.
I don't use snippets, as I don't like that kind of help, but I do use Github Copilot which probably does a more decent job in helping to work with PowerShell.
0
u/BigHandLittleSlap Nov 01 '21 edited Nov 01 '21
It's not like I haven't gone down this road before. You're trying to be helpful, I get it. I tried to be helpful once before too, and got told I was wrong.
You see, there's a 30+ year old bug in how UNIX (not just Linux!) terminals handle the clear screen command. A bug. A clear, obvious, fucking duh bug. If you search for it, and know what keyword to look for, you'll find multi-decade-old arguments about finally just ripping the bandaid off and fixing it.
There are arguments going back as far as pre-www-era newsgroups. Pre-Linux even!
Thankfully, this bug never manifested in Windows. It was correct, probably by accident more than design, but that doesn't matter. It did the right thing. It did the right thing that UNIX people agreed with, but were too afraid of changing "just in case it broke something".
What did the Windows Terminal and the VS Code idiots do? They copied it. They copied the UNIX bug into Windows. For "compatibility". I raised this, with a nice neat ticket and everything. How it broke common workflows. How UNIX people agreed that this was incorrect behaviour and needed fixing. I tracked down arguments showing that fixing it doesn't break anything of import.
Nope.
They just weren't interested.
You see, some fuckwit at Redmond had decided that they need to appeal to Linux users.
Bug.
For.
Bug.
One at a fucking time, they plan to introduce every bug, quirk, issue, and nonsensical design wart from Linux into Windows. They're starting with Windows Terminal and VS Code. Next thing you know, Notepad will use VIM key bindings by default. The Linux users of the world will cheer this on. The Windows developers will be told to shut up and accept the "standard".
Why in God's good name would I spend my precious time on Earth arguing with people like this? Why would I submit tickets, get into arguments, and burn precious hours of my one time on this planet?
They've made a decision.
Apparently I'm wrong for having a dissenting point of view. Along with 100 million Windows developers that agree with me. And most UNIX developers also.
PS: Do a bunch of "dir" commands. Then type "clear-host" in VS Code or Terminal. Scroll up. Why can you scroll up despite clearing your terminal? Because morons.
2
u/MadBoyEvo Nov 01 '21
See, iāll be helpfull again. This is the default, but actually in vscode powershell settings there is a checkbox that fixes it. It was added 1+ year ago because people wanted it and reported it. I am on mobile so canāt check now, but its pretty easy to find. Go and enjoy code š
-1
u/BigHandLittleSlap Nov 01 '21
Found it. In a list that's not sorted by anything in particular.
It has a typo in the description.
Sigh... I mean... just ugh.
This is what happens when Microsoft fires their entire QA team and hires Linux fanboys to do Windows development.
2
u/MadBoyEvo Nov 01 '21
Report it⦠its that simple. I know its easier to just play the blame game, but if we dont do anything - it wont be fixed.
-1
u/BigHandLittleSlap Nov 01 '21
"Please do QA for Microsoft. They won't do it for themselves."
In other news, the billionaire Pope needs your donations.
1
u/MadBoyEvo Nov 01 '21
So you write a long description of your problem, I tell you it's fixed 1+ years ago and instead of "Thank You, that is great!", you go complain about a typo and blame the QA.
Just a reminder - It's a free product, open-source, that nobody forces you to use. You can use other products - some free, some pay as you want.
Here - I've created a PR that fixes this typo https://github.com/PowerShell/vscode-powershell/pull/3658 so you can have one less thing to complain about when this gets merged.
0
u/encogneeto Oct 31 '21
Iāve always avoided ISE because it took forever to start up. Maybe itās gotten better? Maybe I should skip over it and go straight to VsCode?
Anyway Iām just using a powershell shell and Notepad++
What are all the reasons Iām doing it wrong and reasons I should be doing it better?
3
u/cheffromspace Oct 31 '21
An IDE, when configured properly, gives you syntax highlighting, real time code diagnostics, auto complete/intellisense, code lens, debugging and more depending on the language.
You can write PowerShell in any text editor but it just comes down to productivity and developer experience.
1
u/Thotaz Oct 31 '21
What are all the reasons Iām doing it wrong and reasons I should be doing it better?
I'm guessing your commands/parameters often don't have the correct casing and you end up with more syntax errors than your average ISE/VS code user does. I'm also guessing you spend a lot more time writing a script because you have to look up more documentation and go back and forth between the console and script window because Notepad++ won't give you real auto completion of properties, variables, etc.
-7
u/TheRealMisterd Oct 31 '21
Couldn't figure out how to use vscode. Have been on PowerGUI for the past 10years! Way simpler than vscode.
163
u/adamdavid85 Oct 31 '21
I use VS Code exclusively and don't quite understand why one would need to run in ISE aside from "old habits die hard." š¤·š»āāļø
Git integration, Pester support, flipping PS version environments... it took maybe a week to feel comfortable after flipping from ISE in 2019 but I couldn't go back to it now.