Optimizing Visual Studio Code for PowerShell, 2023 Edition by Justin Grote

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] get started you guys hear me okay back there excellent thank you uh so welcome everybody my name is Justin Grody I am here to present to you about optimizing Visual Studio code for Powershell um I'm not going to do the usual pull of how many people have used Powershell or how many people use Visual Studio code how many are still using IC Etc because honestly at this point like it doesn't really matter like if you still prefer to use ISE I totally understand that I've been using vs code for about now about five to six years and I've found ways that it just really helps with my productivity flow so I'm hoping that you know if you do you might see some things that might be helpful but this is not a this is not a used vs code or you're a terrible person you're like you know it but this might just give you some ideas like if you're still kind of thinking about it you're on the fence you maybe you know because it is a big shift I mean I did it like five six years ago and it was it was painful I mean like I had to relearn how to do a bunch of different things but I mean I can unequivocally say that just like how Powershell you know the sacred valve Powershell is you know you take the time to learn Powershell it's one of the best things you'll do for your career because you can use it everywhere I did that 15 years ago and it's I I'm still here just very much driving a powerful career with Powershell learning Visual Studio code was the second biggest thing that I heard did because not only do I have this great tool for Powershell but now I also have this tool that when I need to do typescript when I need to do C sharp and I just want to dabble with them I don't have to learn a whole new jet brains or any of that kind of stuff like I can just use the tooling that I know and the time the time that I've invested in that helps carry over to all these other things so so most of this presentation is mostly just going to be a lot about going over some neat little tips and tricks on how to optimize the environment one thing I want to emphasize this is not a getting started with vs code presentation this is this is we're going to go into the Weeds on a bunch of stuff we're going to go into a lot of what's happened in the last year which has been a ton and just show off a lot of really neat cool stuff stuff that I just stuff that I've learned from my experience spending a bunch of time in it over the Year little tricks that I've found here and there and hopefully help you like get some thoughts and thinking about ways you can use Visual Studio code to you know make your Powershell experience even better but that being said like if you've never seen Visual Studio code before in your life don't panic like even if you don't understand a word of what I'm doing up here you're just gonna see little things here and there you're like oh that's kind of neat like I can see like how that could help me but like you know you don't have to feel intimidated like you're going to be totally lost with the stuff that we're doing here we're just mostly just going to go through just a bunch of fun little neat things it's going to be very demo heavy and we're just going to just go through all those kind of items well that was my presentation who he cares about slides uh so my name is Justin Grody I'm a data center Solutions architect and Microsoft MVP um these are sort of Just My Links so basically pretty much I put a lot all kinds of stuff that I fiddle with and make up out there on GitHub and so that's my GitHub GitHub has this feature called gists if you're not familiar with them which are just sort of like easy little like one-off scripts they are actually full repositories too but I put a lot of stuff out there lots of little handy little scripts and bootstrap scripts and little ideas that I have and then of course there's my Twitter I post all the time about stuff that I'm doing um you know trash on opinions I've the nice thing about being an MVP is I don't have to tow the Microsoft line if I don't want to so like if there's stuff I don't like I talk about it so um yeah so those are my main links and so yeah so if you want to follow me you want to see my stuff there feel free I want to give a special thanks to Ally digital my employer which sponsored my travel to be here and they've always been a great support of me um big multinational MSP I've been with them for 15 years you know our main thing is you know there's a big talk that we always talk about is you know the whole thing about build versus buy if you know if you run a business your core competencies that's where you make money like you don't you don't have a electrical department you don't have a sewer department you you contract those out to utilities so these days even more and more you can do that with it and we're the we're the people who are there for that you have your core competencies you have your main things your core line of business applications but you don't want to you know your focus is on your applications and not your infrastructure basically what we do is we take over that portion of it and so we do that we big you know big global company all kinds of that kind of stuff great company to work for I've had a great time with them so if you have an interest in that kind of stuff check them out and again thank thanking them for helping me to be here today um so this is kind of becoming sort of like a pseudo series I've done did this last year and I also did it at pscon for you um and I think I have a third one that I didn't have up here that I did for pwsh 24. um actually I think that might be the one on the right but um if you just Google like optimizing Visual Studio code for Powershell in my name it'll probably come up loads of extra tips I'm going to try not to most of the stuff that's in those I'm not going to cover here but if you want to learn some stuff about neat little settings tweaks settings files all kinds of cool little extensions great presentations to go back and check out um for this presentation I'm going to do a bunch of different little samples I have a repo out there which is just on my GitHub just ps7 2023 demo I'll get the slide in there too so you'll have all the links and everything um it's it's not a very complicated there's just like a couple scripts they're just sort of sample scripts but they're nice things that you can maybe just take and then run in your own little vs code and kind of see the same demos like I did then the link at the top I honestly completely forgot what that is um oh I never that is my settings file so um if you go to that link it will take you to a gist that is my vs code settings file and it's like five it's like a thousand lines long at this point because I love to tune and tweak every little thing I can and not just in Powershell so if you want to look like you know because if you ever go into vs code there's a massive ton of settings it can be super overwhelming you don't know what's good what's not well I've invested a whole bunch of time in playing with the stuff that I like so for my personal preferences you can go in there and see things you might just might see something like oh I didn't know you could do that I didn't know you could undock the debug thing and have it just float around so that you don't have to have it stuck over there it's a little stuff like that so that's a good thing to go through and if you go through some of the past presentations one of my past presentations was basically even those a couple years ago there's a lot of new settings one of my past presentations was just kind of going through each one of those and it was all commented with like why I chose this it's like why I like this why I don't what's there what's not that kind of a thing all right so here's vs code this is my vs code so it's got a few things that are a little different than out of the box I'm one of those weirdos that likes the activity bar on the right and the reason why I like that is when I do this kind of stuff my code doesn't move back and forth I hate that like whenever I like open something my code jumps it goes back it goes here it goes back I want all that stuff over here now that being said one of the really nice things that's been added to vs code is if you do Ctrl shift p by the way if you don't know Ctrl shift p I also like I think F1 they now make so that's like much easier but I'm you know I'm I'm still I'm my old cranky you know I'm very bad at learning new tricks but this is what's called the command palette in vs code and so if you've never seen this this is basically just Google for vs code like everything pretty much everything you can do in vs code is in here like if you scroll this thing this is going to take me watch that scroll bar over there you know we could sit here for probably half the presentation for everything you can do because pretty much everything you can do in vs code is in this menu but it all autocomplete so if you want to do debug you're going to do that kind of stuff what the heck was that but um so the kind of thing I want to show is first thing I want to do is turn on screencast mode because I have a big thing circled over here to remind myself to do that so again as you type things like it'll figure just it does kind of fuzzy matching and it finds everything that kind of matched what you typed so one thing I'm going to turn on here is screencast mode so you can see it when I do little keystrokes and that kind of stuff um one of the other things I'm going to do here is I'm going to show this thing there's this new thing called a secondary sidebar so you have sort of your main bar you're pretty used to that but what they've added is they've made a new additional sidebar that you can put anything in there now I have a couple things in here I like my little test extensions that go in there I like there's this thing called thunderclient which is a really cool rest API tester it's really handy for like when you just want to like test the thing and see like what result you get back and it's got all kinds of funky cool things definitely something worth checking out that's another talk though but what's neat about this is you can just drag and drop the stuff wherever you want so if you particularly like to have your Source control you can just grab that guy and take your um or take your not that there take the take your Source control and take one of these guys and bring them over why is this not being happy with me there we go so you can have your Source on one side while you have that over there and so it's all really nice to just kind of drag around and picture however you want to organize your stuff sometimes one thing I know that's pretty popular once I get this guy back where it belongs um one thing I know it's pretty popular is to take this thing called your outline View and bring it over here so that you have your files on this side but you have like the outline of the file that you're working on over here and you have this really nice way of like looking at your code especially if you like have like a really long Powershell script this is just sort of like a nice sort of like summary of where things are and you can kind of Click through them so just something to keep in mind like this little sidebar is just another place to put things and it's really easy to bring in and bring out it doesn't have a default key bound to it but like I the great thing about vs code again it's Ctrl shift p for everything they type keyboard you have this preference for open keyboard shortcuts and you can go in and Define a shortcut for every single one again this list is just as long as the list that you saw earlier when you do Ctrl shift p and then some and in here you can make a shortcut to anything you want um so I like I have a shortcut that just very quickly like expands and contracts that sidebar as a thing so it's a very handy little thing to have and just keep it in mind so you can have this kind of nice little you um one thing I'll go over again is that vs code one of the greatest things about vs code is that it's built for extensions and the way that the extensions tie into vs code allows them to do pretty much anything and so there's a massive ecosystem of extensions to do pretty much anything you could possibly want you know basically if somebody's built it you know it's going to be available and so one thing I've made is this thing called the Powershell extension pack um how many of you guys have installed the Powershell extension Packer sought okay awesome that's that's pretty good yeah this is starting to kick out there like 20 000 downloads not too shabby I'm pretty happy with that all this is it's literally just and you can make these it's just basically a glorified Json file but this is just my opinionated thing of like hey if you work in Powershell and you do development probably in a source control like GitHub these extensions are going to be useful to you and so when you install this pack it goes ahead and just automatically installs all these extra extensions that I think will be helpful for you and in addition but you don't have to install them all like you can go in here and selectively you can just look at my list and then selectively choose them out of there and so that's a really handy way that like if you're just getting started with Powershell and you just don't know what's out there you just kind of want to get a sense you can just install that Powershell extension pack and it'll bring in all kinds of stuff from markdown and all kinds of fun coloring and all kinds of other stuff to give you an idea of like sort of more what's possible when you really want to get Beyond just like the initial starter of vs code so um one thing I want to cover that is a new feature that is helpful to pretty much anybody even if you don't even use git like if you don't even use git at all if you if you just still write your scripts on file then like that's totally fine one thing that um has been added to vs code which is super helpful is this thing called the timeline view so in your in your timeline as you go any file that you have on your file system that you're editing in vs code every time you save it it's going to make a backup for you and you can see it right here in the timeline so for instance this this completers demo I was working on so we go back to the beginning you know not a lot in here but you can go back as long as it keeps history and you can see each step of the way and what was um what was being my mouse finally died I knew it was going to die on me it was like on its last leg so we're switching to touchpad here um yeah so yeah the funny thing is yeah does anybody have a micro USB cable that relic of of 2021 like God forbid I flew up here I drove up here and like of all the cables I packed it's like the first time I packed like all USBC cables and totally forgot that my mouse doesn't use it at all thanks man appreciate it get that man a t-shirt yeah all right and we're back probably here in a minute we'll see all right anyhow so the really nice thing about this is that as you can see not only do you see um you know the previous versions but you get this nice diff view that'll show you what you changed at that time that you saved so if you're ever working on a script and then you you know you get your script you know I've done this a million times it's like you get to work on a script you get it like good enough like it's working but it's like slow or like you don't like how it's laid out so you're like oh let me try something else and like like that that's good that works I'm ready to ship that but let me try something else and I go in I go through and I edit and I save and I'm not paying attention I'm not like committing as I go and then suddenly like I do my new thing it doesn't work but then like okay now I need to get it back to the where it was working but oh crap now I can't get it back to how it worked because I forgot like what I was doing or I'm missing some character somewhere so what this is really nice for is like you don't even have to think about it it's there for you and if um if you know if you end up in that situation you can just simply go back and see oh okay I can go back at a certain time and just say like oh okay there's The Verge there's the version like before I was doing any of that kind of work yeah you had a question does the timeline follow along if you're also doing stuff yes it does and there's actually a really nice new feature this is very new that I was going to get to a good segue called Cloud changes if you turn this on it will synchronize it across all your vs code instances wherever they are so like if you're doing a vs code on a work computer and assuming they let you all sign into the same Microsoft account you can turn on cloud changes and even like this will even include like if you have an unsaved file in your editor like you haven't gone through and saved it yet it'll keep that in sync for you if you if you enable the certain settings for it so that you can close your laptop at work you know and then open your laptop in a completely a completely different laptop that you know as long as you're signed into the same vs code profile and those unsaved changes will show right up so yeah really cool stuff it's sort of built on the sync engine that they uses it uses all the same sort of sync back end but yeah really cool feature brand new fairly brand new check it out and it's really simple it's literally just turn it on you select the account that you want to use it with and then it just starts running uh um another really nice new feature that has been added is the concept of profiles so in the past like if you have a vs code thing and you have like a project you have like your personal settings and you have like workspace settings and you also have like if you do like a workspace file you can like do different settings of the different projects so there's already like a pretty robust like hierarchy of how you can have settings and things but one thing that comes up sometimes is like especially if you're like you know if you work across a lot of different languages um a lot of times you'll have a big bloat of extensions or you might have certain settings for certain profiles like you have some customers that they want you to write all your you know they want they want your uh Powershell formatting to have the the bracket the brace right next to um right next to the function or whatever whereas you may have another client where they want the brace where it's like indented and then you tell them okay well just set me up a PS script analyzer settings file in your repo and they're like What's that so you go okay but you don't want to go back and forth you don't want to toggle that setting back and forth between the two customers so that's basically what this new profiles feature is so if you just go down to your um information your settings gear here and I know that's kind of small I I bumped up the DPI let me let me see if I can redo the DPI again I thought I had this bigger than that uh I thought I bumped it to 150. that's the 150 okay VSCO is just being small so let's try this there we go that's better okay so um over here you now have this little thing for profiles and so you can create these new profiles so what vs code has done is they've worked hard for both not just your um settings but also like your view like how you position things on the screen basically all the stuff that goes into settings sync what extensions you want to have installed and so when you switch to a different profile or you create a new profile it switches to that if it's a different you can have a different theme so you can tell the difference between customers it's a completely like it's almost like a container for your settings and your extensions and everything so now that I go into this one you'll notice like now my toolbar is over on the left a lot of the icons that were there are gone so I don't have anywhere near as many extensions installed as I used to because I'm working in this particular environment I don't want certain extensions to be there because maybe they conflict or maybe they cause my vs code to slow down because they weren't written properly to activate so um and that's like I just want the Powershell stuff so it starts up fast and it does that kind of stuff and I have my own custom settings for this and you see down on the icon there there's that little de for demo so these also work with settings sync so if you make a profile it'll go into settings sync and so you can go to another computer and still have that profile and what's really neat is these are exportable so you can set up an environment just how you like it like you could set up a reference environment for somebody coming into your environment and you can just click this export profile and you can choose the individual items you want to export and it'll dump it out to a Json file so it's a little bit more than just the settings Json file you'll see it even includes your UI state so you can set something up where remember I said like the side panel like you want to have certain things in this side panel and over there you can save that state as a profile and then give that to somebody and give them like that view and so that's a really helpful thing really powerful for like getting teams to be on a consistent thing easy way to like get them restored and this works with code spaces I'm not I'll talk about code spaces a bit but basically it's just a way to run vs code in a container and there's lots of ways to do it code spaces and Dev containers but you can add this so that when somebody first comes into your environment they can get like the view that you want them to have of your repository in terms of where the tools should be and such like that you know that gets really opinionated we all as developers have our own ways of like how we like to do things but it's just sometimes it's nice to know that it's there's an option if not so much for like oh I want you to work the way I do but more in terms of hey let me give you like a preset of vs code so you don't have to this stuff out but check this out like you've already got the test extension and it's there in the corner and it's I've already added the settings for you to you know bring in the special version of.net that I need to write the certain thing I have or or you know I have it set up so that it defaults to Powershell seven instead of Powershell five one so you don't have to learn how to toggle that kind of a thing so really neat new thing the settings profiles are there and this also enables you know not as not as like direct to you guys but one thing that's really neat is on the command line there's now things where you can do like dash dash profile and select your profile that way and where this comes really handy is like so I do some contributions to the vs code Powershell extension and like I'm not a member of the Microsoft team I'm not I just I have some frustrations and my code is very much like my house like it just like I have frustrations just like my house it'll just get dirtier and dirtier and dirtier and then there's going to be a point where I just snap and I'm just going to clean the whole damn place up and that's how I am with like features like with with the debugger a few debugger feature which I don't know how many you guys were in the vs code presentation yesterday with the team okay that's pretty good so you know they were talking about the depot they kept pointing to me they kept being like Justin added this feature well that's me that's me in my house after probably about two or three months of being super frustrated that it wouldn't do this thing to the point that like you know what I can't take this anymore I don't care if I have to learn if I have to spend two months learning typescript to figure out how to write this stupid thing I'm gonna fix it because it's driving me crazy that's how half that stuff comes in there anyhow um that's a long way of talking about so with profiles what you can do is that in the testing you can make it so when you test an extension you use a profile sort of like a temporary location you didn't used to be able to do this before you basically like it had to share your settings so like when we were run tests it would screw up all our settings so you can make these little isolated environments for actually testing the UI of vs code so we added in a bunch of that test scaffolding to the vs code extension and it makes it a lot easier for us now to like test test features that actually like can you know be verified that they work right in the extension without the test being really difficult if you're in that presentation they talked about spending like months and months and months of rewriting the tests most of that was actually in like the C sharp part of the extension which is called Powershell editor services but the actual editor part of the extension like the client part still like the tests are still still kind of loose because of this limitation but now that we were able to take care of that we were able to kind of get a lot of that stuff sorted out so that stuff should move forward a lot faster not something that's like super relevant to you I know but it is good to know that like profiles now is this really nice feature that took a lot of work but is now has this ability to really isolate your settings be able to let you distribute them distribute a profile and allow you to have those different environments without having to do the sort of hacky stuff we used to have to do like use peacock to like say oh in this folder you know just dynamically change my theme so that I know this Windows this one and such now all that stuff works great and it's built in um so we'll move on to another item that was added that is super helpful for Powershell um so one one common thing that comes up is like when you're going to start a new Powershell project in vs code um how many people like have oh do you have a question I'm sorry thank you yeah my profile so I have my settings Json out there I don't really have I haven't really exported my profile because it's um it the Json is really hard to edit and there's some private stuff in there that like I would have to go through and I'll if like I'll tell you what like I will go through there and I'll sanitize and I'll put it out as it is like it's always changing I'm not going to keep it up to date because it's just a pain like I would have to write a Powershell script just to sanitize the thing but um I can put a version of mine out there that's like yeah and so if you import my profile you'll get like where I put my test thing and where I arrange stuff so you'll open it and be instantly lost so if that's what you want feel free but yeah I can do that so but yeah but if you want to share them like again you can export that Json and like I say you just throw it up on a gist you know you add a bitly link to it it's like hey do you want your vs code to look like mine does when you do a presentation just go to this link download the Json and import it and all of a sudden it'll automatically re-magically do your vs code to look like they did and you don't have to do a lot of like Pro you literally just you set up the VS code how you want and then click export you don't have to like learn how to like edit a Json to do it so um yeah real really nice feature um and it was it was a it was an item that was there for like a long long long time on the list so all right um one other not one other we're gonna do a lot more than one other but uh next item is on these things called so the question that I had for you guys was who here's ever actually like done debugging in the vs code Powershell like have you ever run a script gone to a break point great so when you first open vs code most of the time like the first thing you have to do when you start a new repo is you got to build that launch Json so that that stuff actually works right like you got to go in and you got to click like add configuration all that kind of stuff so what you can do now I'm going to do control comma which is the fast way to get into settings and I'm going to flip over to the Json view because that's how I roll oh and again and then again here's kind of a neat thing is like you can both see your personal settings and then you can go to like whatever your current profile is setting so actually I probably just need to go back to my other profile but you know you don't even have to restart vs code like I'm just going back to my other uh settings here and it should it's probably going to lock up here while it moves everything around yeah but see it it just reapplies all my settings and goes back to this is how I like my vs code that other one was basically a default plus where I just added some stuff um so what we can do here is I have you know a lot of times when this does it too like it's not perfect sometimes it helps just do the reload I do this one this I do this reload window so much I bound a custom key to it because like I all the time I'm just like nope restart if you don't know this command by the way this is this is like one of the best commands in vs code it's basically a way to like reboot vs code without having to close it and reopen it so if you just develop a Reload window like I binded to a key so I just have to control alt R there's also another one that's pretty helpful not as not as necessary anymore because it's become much more stable but uh it's probably not good so Powershell restart session this will restart your power shocks and same deal like it so like I do F5 to like run my scripts so when I get angry I smash two more fingers under control shift and then hit F5 to make it restart it and do it correctly this time um that's how I always remember the shortcut and so this is just really helpful this will just restart your whole Powershell session so like if something gets screwy your intellisense isn't working that one's a really good go-to and you know even just like six months ago like you know I would do that all the time I almost never do that now like if the extension's gotten so much more stable those debugging pipeline improvements that they were talking about very difficult stuff that I don't understand it takes real gurus like Patrick seemingly science on Twitter you know those guys those guys every time my favorite thing is um as a little side note like if you ever talk to me in the Discord I I call myself I'm the Cunningham's law guy whoever knows what Cunningham's law is okay good so if you don't know what Cunningham's law is it is the best way to get an answer on the internet is not to ask the question it is to post the wrong answer and someone will correct you so if you come to the Powershell Discord you will ask a question I will very confidently ask you oh yeah this is how you do it and then Patrick or Chris will come in and they'll be like no idiot this is actually how it works I'm like I'm sorry so um uh but yeah so those guys those guys really know their stuff and I I look up to them all the time learning you know they help me all the time and Mentor me through a lot of this you know that's of learning how to contribute to vs code Powershell I mean like those guys just helped me and mentioned me all I did was just ask for help on Twitter you know so this is that's one way you can get into this kind of stuff um but yeah but again the point of that long diatribe is that they have done a really good job of really improving the reliability you guys have probably noticed like it doesn't crash as much it doesn't get stuck as much it's much better at handling like debug situations going in going out and there's always more to do but like I'm really happy with especially in the last um eight months to a year how really good that process has gotten so I'm going to shrink this down just a little bit again um well not that far is that still readable for you guys in the back sorry we got the long room this time as opposed to the wide room so yeah okay yeah we'll go just a little bit bigger uh so the so to get back to the thing of user profile debuggers uh we'll just go down here and I have to find it in my massive configuration file here okay so you can now Define this new thing called launch so if you define a launch header you can define basically this should look just like your launch Json so you can Define at the user level your launch configurations so no matter what repository I'm in I have these particular launch things like I have one to Just Launch an interactive session so I can just do stuff and if I happen to hit a breakpoint it'll stop there I have one for just running a file I have one for running with arguments I have one for pester tests you know that kind of thing well you'll see all these over here if I go to run I have no tasks Json in here I have no anything like that but if I go over to my run I always have these options here at the top where it says user settings and parentheses so I always have these Powershell options for debugging and I don't have to go set up a launch Json I don't have to touch somebody's repo and add in that launch Json you can just add it to your user settings now so it's this exact same format as when you do it if you just want to if you're not comfortable with like this format then all you just do is you just go and you create a new launch Json and let it you know there's buttons like ad configuration and you can pick what you want it'll like autofill it for you you just cut and paste that into here it's the exact same format it's literally the exact same schema and so if you do that so you know here's the ones that come from like the vs code Powershell here's a couple that come from a test thing that we're doing here's a couple that come from my little chat GPT module Powershell assistant but at the top always are the ones that my Powershell ones are always there so it doesn't matter what repository I'm in I'm always able to just immediately debug Powershell without any yeah oh did you have a question I'm sorry yeah so the question was like if you enable the user settings launch Json does that stop the pop-up that says hey we're not sure if you have any uh hey we notice you don't have any launch configs would you like to create one I honestly don't know I mean we could try it we could just start a new repo and find out here uh we'll um yeah we'll do it live okay am I good hey all right I got a mouse again thank you very much sir and so we will I mean we got time so we will we are doing pretty good so we'll just uh I always like to just my way of doing things is like in my folder I just make a folder called projects and that's where I put all my stuff and if you look at like if you open up my windows terminal I don't know if this has my custom terminal on or not yeah I got that in there so like you know I do a local I like I'm a less is more kind of a guy I like I I don't like like the prompts that have like 5 000 things on them I like it to be contextual like if I have a git repo show me something otherwise all I want to see is that I'm home like I want I want a Zen mode of like focusing on what I'm doing so rather than see my home just as a home but if I go to projects this is called oh my Posh by the way is you've probably heard of it prompt customization this is my version of it because you want to go to projects it doesn't show like home slash projects it shows me a little construction icon and that's just I just know that okay I'm in my projects directory and then like if I go to Powershell now I start getting I'm in Project slash Powershell assistant so like that's how I work that that works for me you know everybody's different but so we can we can do a new repo here we'll do a Victor does launch configs annoy you and we'll do a code dot which will just start a new vs code in that folder well that does not read as well as I thought it would in all caps uh test.ps one it does so that should trigger my Powershell extension to start and we will reopen it again so are you talking about like when you hit debug for the first time so it's like when you hit debug for the first time it asks you right yeah well I didn't get it this time so I guess not I mean like so but like the runs are here so like I have this interactive so I can just say uh start this and we'll do run and hit start and so so again with zero there's no launch tests or launch Json in here like it's just coming from my user settings so really good you know if you're just messing around with things making new folders doing all that kind of stuff like you know you can now not have to avoid that boilerplate step makes you just that much more efficient get stuff done faster yeah um so let's see uh I got one more thing actually I think this will be so at this point like does anybody have any other sort of like general questions like of what I've liked having covered so far we move on yeah the timeline view thing right okay let's go back to that doesn't require git uh so the question was that with the timeline view uh it doesn't require git so where is it storing these revisions it's storing it in your user local state profile so if you open up your local update if you go into vs code there's a folder in there that'll have all your previous revisions so it's stored locally so yeah if you take the computer and throw it out the window yeah you lost that code it's not being backed up in any way unless but like if you put that folder and you like Sim link it to OneDrive then all those revisions will be backed up on one drive and you can get them that way too but ideally you're using Git You know you're back you're using that to push to remote but you got and if you enable the cloud changes then it'll back up those up those timelines to Cloud changes as well so uh but yeah but it's it's basically just automating the process I mean again the old school way of my script my script copy to my script copy three it's just automating that of what we used to do that way it just makes it so that it hitting save it's basically just saying taking that one and making a copy to and putting it over there so that makes sense yeah all of them have you heard of like that about just growing up commercially you know is there a way I yeah so the question the question is um you know so you do this let's say you have like a 50 gig file and then you go to change it does that mean you get like a 50 gig file every time I do I I don't actually know the full internals of it I do believe it actually does diffing of it so that like it's only that's why I like partially like why the diff system works here but you can see the files and and also like one thing I didn't mention is like you can right click here and like you know again if this is your good copy you can just right click and say restore contents and it'll bring that version back um but as far as like the storage I think there are some like safeguards in there because like this was a feature that was in development for a really long time and like you can go out and look at the GitHub discussion on it and it's like massive so um I don't know for sure I believe that there there is like a vs code setting that's like Max timeline history and I think it defaults it's default to something like I think like like probably something ridiculous like 10 gigs or something well like once you hit that Max then it just starts deleting old history after that otherwise it saves it I believe don't quote me on that but I'm pretty sure that's how it works but that's something that if you go to the release notes for when it came out which I believe is in January there's like they wrote a whole article about how it works so there's there's detail for that is there any way to highlight file save you want to go back to um so it uh the question was like if you are working on something and you're doing timeline is there any way to highlight which files you want to go back to so are you talking about like if you made changes to like five files and you want to go back to like a particular time frame or one file Okay so yeah okay so great example so let's take this brand new file that I just made I made an edit four minutes ago so I make a save and I have that change so you just click rename so you can just say Well when it works on my machine so so you know your guy brings this script and he's like you know he says like hey I took your script it doesn't work anymore well I'll go back to it works on my machine and I can just do restore it's like are you sure because once you do this there's no going back because like again it'll still be in the timeline there but see now I'm restored but then I restore that I'm like okay now I figured out you know it just treats as a new revision so even that previous version where I broke it is still in the timeline so like once you restore now you're back to that new file yeah it's basically you know conceptually it's like as if you're doing a git commit on every save in a way so like and so all the sort of similar kind of rules of plot you can rename a commit you can go back that's not what's actually happening like it's not using git on the back end it's using its own custom thing but you can kind of conceptually think about it that way if that helps does that answer your question okay great any other questions before I move on uh uh so and so the question was like if you're leveraging like Azure functions is there anything you can leverage from like vs code for that um for Azure functions specifically I'm not sure I mean I think I know that there's like Azure functions extensions and stuff like that um I don't know is there anybody here who's worked on that at all I don't think they're here yet so all right well maybe maybe we'll come back to that a bit later so um yeah like I've worked with it a little bit but yeah like um let me think about that for a bit we'll do some other stuff and we'll come back to it um all right so moving on um we have some items around let's go to two completions now so Let's uh [Music] so one of the things that they were talking about in the presentation yesterday if you were there was that there's been all these really great fixes in intellisense and completers and all kinds of stuff around vs code these kind of come from two different sources there's fixes that have been done in the power in the Powershell extension but a lot of these are actually changes that have been done to the Powershell repo so there's this guy and let me see if I can pull up the Powershell repo here real quick that that is not the Powershell repo wrong wrong Powershell repo and there's let's see if we go to the commits uh so of these let's see I well I'll figure out but yeah I I had a view that I had saved here but basically there's this guy Martin gc94 on GitHub nobody knows who he is like he doesn't have a Twitter he doesn't have like he doesn't respond on GitHub but this guy has made all these contributions to the completion engine he has fixed so many bugs added so much cool stuff and we all just want to like highlight and like you know I'll give him a shout out on Twitter but like nobody knows who he is and he never responds but he makes great PR's all the time and they get accepted because they're they're they they change UI stuff so they don't like break scripts so you know you know Powershell repository is notoriously works very hard to be backwards compatible so any little change to the language can have huge impacts on you know scenarios who knows how people are using it but you know for stuff that just like changes the UI and how you edit scripts you know that's kind of a low barrier so so a lot of these PRS are getting accepted all the time and so he's fixed all this great stuff and as a result it carries through the Powershell extension so whereas a lot of this stuff just works at the CLI these things can also be utilized in the Powershell extension because a lot of how the Powershell extension does its completers and all that kind of intellisense stuff is literally just like calling a Powershell API basically asking the Powershell CLI hey how would you complete this and then bringing it into vs code and doing it in the nice graphical way so I'm going to go through a few of those because if you've been using the Powershell extension and you haven't like seen these commits you might not know that this stuff works now because you might have just done it and then realized oh that just that just doesn't work anymore and so like or it's just broken and it's just always going to be broken like I do that all the time like I'll come back to something and just assume things are broken and then find out oh no this all stuff works just fine so so we're just going to go down sort of a list of a bunch of these different sort of completers that are now active so one is that I like to start with because it's got to be at the top anyways is um using namespace completion um if you haven't ever used this this basically makes it so like who has ever written a script where you put in you have to use like a.net type but you put it in as like system.management.automation dot dot nextlevel dot next level three dot nextlevel4.myitem you know in your script all of a sudden you have one line that is just this giant.net type so if you don't know you can use this using namespace keyword at the top of your script if it's Powershell five or later at this point I think I should that should just be the de facto I assume that you're not writing in four or three or two anymore you know and if you are you already know that this is a problem for you so I'll probably just say you know well just the de facto so you can now on every supported version of Powershell that's what that's the way I'll put it there we go um yeah you can actually use this using namespace keyword and if you put that at the top of your script this is sort of like sort of a C sharp kind of kind of thought but but it kind of got carried over to powershells like if you put using namespace at the top then you can put like that whole prefix part at the using namespace and then in your code you can just do the last part so you don't have to write that whole thing out so your code becomes much more readable you know in terms of like yeah uh I believe that I don't think there's like a super easy way to do it like there's not there's not something like in typescript you can do something like import this as that I don't think there's anything specific like that typically what I do in those scenarios is I go one level up so like the one thing that I'm doing that's my main thing that's like you know you know component one component two then the thing that conflicts then in my script I just go one level down so that it's you know my module dot component one my module dot component two so you can tell the difference but I don't think there's a way to do like specific aliasing um it's too bad Patrick's not here because cunning's ham law would definitely be applying right now and he'd be like he just raise his hand and he'd be like this is how you do it so I'm sure there's there's some way to make it work I just know it's not like it's not like a probably like an easy built-in language thing anyhow so so the point of this being is that you can have that but sometimes you got to know like what is the namespace that I can use so if I you have a terminal you know if you're going to do a type here oh I probably don't have my do I have mine extension going okay you know so if you're doing something like system management so one thing that you all probably know is that any.net type that's in your thing this all already gets Auto completed so like if you're doing this you're like okay good I can kind of find my way down to what I'm trying to do like action preference for instance and it but what's nice is up here this now Auto completes so if you're here all of this stuff now Auto completes this didn't used to work so you can kind of get down to what you want a really common one is like you know people like to use like you know like generic lists as opposed to using like arrays because they can be faster in a lot of situations by a lot so if you do that then instead of having to do what you see in code all the time which is system generic list string RX equals at like that now you can just do or sorry system.collections dot generic list now you can just do list and that will work fine so if I copy that paste it in take this guy so you like it doesn't give me an error saying I don't know what this type is because because you can basically put that namespace in there make your and you know this is a lot easier to read especially if it's like in the middle of a code block oh it's a list of strings as opposed to it's a system.collection.generic DOT you know whatever list of strings um but that completion didn't work so that's you know it's a little thing but it's nice because it used to be like oh you'd have to look it up and maybe you misspelled or any of that kind of stuff you just have typed the first couple letters hit enter and then not worry about misspelling it so this works for requires as well so with the requires parameter which allows you to specify in a script um you know you get to say like hey if you don't have this module this script just won't even start or if you don't have this version of Powershell so all of the required stuff now has Auto completion so if you do the dash you can now auto complete these and if you go to modules and you do it it will auto complete the modules that are currently installed on your system so you can just select the one that you want to require as opposed to having a guess and again maybe make a typo maybe not paying attention can't figure out why your script is starting and then you realize you put an L where an I should have been and you know you take forever on that it just it's just little things like that that like it doesn't seem like that big of a deal but once you get used to it you're just tap number one like you're you're using less keystrokes because you're just hitting tab to complete it and not writing the whole thing out but you're also ensuring that you're getting the correct thing that you wanted and just avoiding a dumb error you know you just it just saves you just that it's just that much more time that you don't spend five minutes going oh I put a i instead of an L there and it just makes you that much more efficient optimizes your vs code for Powershell hey look I said the title it's that's I love it when they do that in movies when they say the title of the movie in the movie I'm always just it's like it's like that uh what's that that um that uh Once Upon a Time in Hollywood like the Leo the Leo meme you know just like that they did it um so another thing that was shown in the thing I'm going to go ahead and bring that outline view back up here again except in my sidebar because I moved it so you know all my stuff screwed up thanks to you guys I gotta bring it back where I like it I like it over here because that's how I am um so one thing this is something very very new is classes didn't used to be a sort of like a first-class citizen in terms of like VSCO didn't discover them as symbols but now it does so now in your outline you can see that a class is there and if you have a class to find you know it's obvious here because it's like right there but like if this was like a 500 line file and you're like where does this dog type come from you can you know you can do the go-to definition and take you right there or you can do the peak definition which will without leaving where you're at say hey this thing is defined here and then if you want to go there you can just double click it and then it'll take you there so this always worked for functions this worked for other things like that but now it works for classes and so you have all of that and as a result because of that you also have the ability here um when you're come on Terminal what are you doing oh because I haven't done the class this is my problem I never use f8 so oh I don't have f8 built on this keyboard let's go back here oh I know why again because I'm a super special Snowflake and I don't have f8 down there because I want to be super special and I make my f8 control enter shift enter but now it overlaps there we go it's Alt Enter that's right I changed it so like for my my for my f8 I rebounded to Alt Enter because that way I can like enter enter and then Alt Enter to run the code except now I just completely forgot about that because I've been doing Demos in basic vs code and I hit f8 all the time like why does my f8 work anymore it's because you Unbound it doofus um okay so anyhow to get back to where we were so now I just have the classes here but so now you have the class but now I have autocomplete for my classes so if I have Spock and I do dot I get all the properties of my class I defined so again I don't have to guess what my property is I don't have to make a typo I can just go there and get it you know status the goodest of boys for sure good as well I cannot type today so there you go so now you have like autocomplete and type reference for for class parameters so if you define a class when you go through the rest of your code you can make sure that's one of the really nice things about classes like when if you start getting into like strongly typed languages like like typescript and c-sharp and that kind of thing one of the things you end up really kind of missing in Powershell is like hey once a type is defined or I'm using something I don't have to remember the parameters that are on it I just hit control space and it just comes up and I don't have to I don't have to guess I don't remember I have to look it up I have to go back to the code I just hit control space and I get that thing um so another thing that's fixed um used to be able for enums so Pia style is an example of an enum and so it used to be if you did a DOT here nothing would happen but now if you do a DOT it'll go ahead and populate the enums and you can pick from them um this works for any enum I just use PS style as an example but if anywhere you have like enums in your code you don't have to again go back and look for the reference hand type you just hit control space and you get the intellisense for it this is the this is one of the coolest ones if you haven't seen this so normally I don't ask this question anymore but you everyone here done splatting before at least heard the term okay pretty good okay not a ton okay that's great so if you don't know what splatting is how many of you have ever written a command that is is invoke thing you know invoke rest method Dash header Dash this Dash that Dash that and you either just make that a totally ugly line you put in those extremely hard to read back ticks to put it make it multiple lines but you just have this gigantic command you know and the other thing too is like what if you how many of you have ever had a piece of code that was like if this do this long ridiculous command else do this long ridiculous command plus this and then whenever you got to revise it you got to go back through there and figure out oh wait which ones are the same which ones are not like it's a pain in the end it's a pain in the butt so excuse me I can never remember like what my levels allowed here so uh so what splatting basically does is it makes it so that you can define a hash table with your parameters in it so an example of get item you can just do you would typically do like git item Dash path this and you might do Dash include Dash exclude so instead you just make a hash table that says include equals what you want the parameter to be exclude equals what you wanted that part would be path equals what you want that parameter to be and you can do any kind of stuff you want there and then if you when you you'd set that as a variable and then if you do this at symbol instead of a dollar symbol it'll take that hash table and basically explode those out as parameters on your command so instead of having this super long command or this really ugly back Ticky thing you have this really nice vertical hash table that's really easy to read very clear what you're trying to do and at the end just saying run this command with these parameters and so that's two major advantages one of which is that you get that nice view it's really easy to like comment out a parameter and not have it rather than have to delete it out or delete it and put a pound comment to the sign like don't forget to put this back in dummy because it'll break the script the other nice thing unless you do is it lets you do stuff conditional so when I say like that if stuff you can have a base set of parameters and again it's just a hash table you don't have to use it immediately after so right after you can say like hey if this thing add this additional parameter into that hash table and you just it's just a hash table let's just do you know you know like say you know if um if it's on this particular file system I want to use Force so if you do that test then you just do get itemporams.force equals true but all the other parameters are still in the hash table so it just changes that logic that way and then you get down here but if that if condition doesn't happen then your hash table is still just your your typical parameters and things just go there so that might be if for those of you haven't used splatting I know that's a lot um so I'm just running through it but look look up splatting it's cool and what I'm going to show you next is real yeah I've never done this before but how do you splat if there's a switch monitor well there's no value uh switch parameters are true false so you just do the switch equals true and if and if you did a switch parameter switch equals false I hate you if I see us just just leave the switch off you don't have to specify it again I'm the I'm not the guy with the prompt with the 5 000 things in it like I know yeah I'm okay with like yeah you don't Alias your things you don't do that but I don't need to see every single one of your switches colon false like don't do that don't do verbose colon false confirm colon fall like just I get it that's the default you don't for me for me I'm always about like you know your code should Express to me what's you know what you're doing and if you're doing something special just show me what you're doing that's different you know you don't have to be explicit about everything it's like you'll see if you look at my code like I will omit pretty much everything that I can possibly omit because it distracts from what I'm trying to communicate what I'm code is for humans it's not for computers you know if we were trying to do everything for computers we write everything in assembly otherwise everything is just abstracted assembly that makes it easier for humans to interact with computers That's My Philosophy so when I write stuff I'm trying to write a story I'm trying to write and that's why I love Powershell it's like I can write in this language where you just look at it and even if you're a business person you can look at this and get a general idea of what it's doing and if you can can't there better be a comment for me saying hey this is really weird code but I'm doing it on purpose because it solves a performance problem or it works around this other problem otherwise it's going to be very clear very expressive and even if I can't do that I'm going to take that stuff shut it off into a function that's very clearly defined you know it says get this thing whereas all the implementation logic is ugly and disgusting but the actual core flow of the code anybody should be able to read it in my opinion all right so soapbox over four you know 40 minutes later we get back to this and so so one thing though is like you know you get this but like how do you know what parameters are on get item well you can come down here and kind of auto complete you'll see that everybody sees this they know that but what you can do now is as long as you define the you define the parameter and then you define the Splat when you come into the hash table and you hit control space you get all the parameters that are from the command so it evaluates yeah that's cool I do splatting all the time and I would typo commands all the time I'd have to go look up what the thing is now I just go here like if I get item and I do control space if I change this to get process and I do control space I get the parameters for get process yeah it didn't used to but again thanks to Martin gc94 God bless him wherever he is uh yeah see name came out of came out that doesn't mean you can't still do name it's just this is originally this would foreign that's a good question uh let's see what's what's a good one let's see let's help let's do a help on get item and yeah so I think path and literal path are separate ones so if I do literal path paths should go away so if you get item Dash literal path nope come on Magic oh it's because I locked up my okay also number number one thing you'll learn in vs code and this is just it just has to be this way there's another way if your vs code terminal is stuck if it does if you can't see the prompt your intellisense is not going to work just just be that aware so if you can't see your prompt and your intellisense doesn't work make sure you can see your prompt that's like one of the number one things I'll get to your question here in just one second so we're just going to see if this works and then we'll go from there so so if we come back down here control space okay so no it doesn't so but um yeah there you go yeah I mean there's no reason I couldn't parse it but there might be reasons you want to okay sorry what was your question uh have you found any good ways to quickly refactor inline parameters to Splatter I've always wanted that and I didn't know if anybody had any yeah there's a guy named there's a guy on the Discord called seemingly science Patrick who knows everything under the Sun so there's this thing called the Powershell editor command suite and it works on the command line as well as Powershell but what he does is that he's written a bunch of refactorings just like that where you can highlight a thing I don't have it installed here because um I I was doing some stuff um in short basically look up actually here let's pull it up here editor command Suite Patrick is rad is what I would normally type but there we go okay so this thing if this editor Services command Suite he adds all kinds of stuff that um as all these refactorings and so you can go in and this will probably demo a bunch of them but so you'll do a lot of code action and it does all this crazy stuff you can do and then when you just did convert command to Splat expression did you see that it went by really fast but that does that I use I use that a bunch so yeah yes there is a way to do that it's not built into the Powershell extension but the Powershell extension has extensibility to do that kind of stuff and he's written a module that uses that extensibility we're hoping to make that a lot nicer right now it's just command palette stuff we want to eventually well I want to I'm not part of the Powershell team but I mean like I want to hopefully if I ever get time on my giant pile of to-do list one of the things I want to do is be able to take all the things that show up in that command palette to do it and convert them to code action so that when you when you get us when you're on a command that's say like you know you can set a preference that says if a command has more than four parameters on it give me a little light bulb and let me click that and say convert to Splat expression like that's what I want to do it's not there yet but it is certainly possible so well again I don't know if you're aware of this but the Powershell extension is open source and you can feel free to open a PR anytime all you got to do is all you got to do is become an expert in typescript to become an expert in C sharp understand all the internal working engines of power shown you can contribute like it's so easy anyone could do it that's why it only took me like five years to make my first PR yeah no it'll parse the whole script so like if I mean I don't know if it works cross script like if you had it defined as a script variable here and you're dot sourcing I haven't like stress tested to that level but you can certainly like you can take this guy and put him way down here and it'll still work um yeah because like as long as it's in scope because what it does is that whenever you make a call to the completion it goes to Powershell and there's a special like git completer API and it's a really simple API it's just simply it's almost like chat GPT it's like it's basically just asking Powershell hey here's the code what could possibly complete this and then there's a whole series of crap that kicks off of AST parsing and and flow rules and visitor patterns and stuff I don't understand at all that eventually comes with the result of here's here's what you can complete it with and all this extent the extension part is actually really light like none of the logic of this is in the vs code part that's all in it's not even in the editor Services part for the most part it's in the Powershell repo like all that stuff happens inside power that's why this stuff works at the command line too like if you're doing a um uh this might be hard to demo but we'll try it test equals that gets item at test see it works at the command line yeah like I said it's it's passing this through in a nice GUI thing but all this stuff works in Powershell too that's that's one of the things I want to note is pretty much every one of these competers if if you're super hardcore and you don't even use notepad you you write your scripts as multi-line command one-liners like it can help you here too this the control space I have a bound to control space I don't know if that's the default still I think it is but um yeah all those same competers work at the command line I'm just demoing them in vs code because they come up automatically for you and you don't have to remember and sorry let me let me let me blow that up a little bit sorry for those in the back so if you didn't see what I did I just basically did the same line of code that I did in vs code but I did the command line and then I hit control space which is sort of like the autocomplete just like when you would like control space a parameter just showing that all this stuff is not vs code magic this stuff works in just your standard Powershell command line the caveat being most of this stuff you need Powershell 7.3 and some of it you need the 7.4 preview so like this is not going to work in five one this is not even going to work in 7.2 LTS for the most part most of these completions are new but you know again we're all Powershell guys it's not that big of a deal to install the current version and um if you're running on the current version these are some of the advantages that you get from doing that even if you're authoring five one scripts If You author them in seven it makes it much easier to author and then you can just use just as long as you make sure it's still five one compatible and test it in five one you know you still get all the power and the ease of use and you can still write five one Scripts or Windows Powershell scripts I don't even know what I'm supposed to call it anymore like I still say Powershell core occasionally I don't mean to okay so moving on to the next item so one thing I've been doing a lot of like when I worked in typescript a lot like a thing I love is like all these things have like implied types like basically in Powershell everything's dynamically typed and that's super useful especially if you're a beginner because you don't have to figure out that it needs to be a string or you don't want to get these cryptic errors that hey this type doesn't match that type like it feels all super anal retentive and like I just want to get stuff done and 85 of the time that's how I am the other 15 of time I'm working on a really large code base and my Powershell scripts I change one thing and now I spend the next three hours finding all the places that of the references that I messed up and didn't figure out and getting cryptic errors getting null references getting all that kind of stuff drives me bananas it's like the most biggest waste of my time to the point that like whenever I'm working with Powershell I'm like why can't I have that stuff I mean I know why I can't but like you know like when I'm like I really like that like if I Define this thing if I just take a little more extra time and like really rigidly Define something that the compiler before I even run this script is going to say hey dummy you referenced a property five scripts over and 20 functions away that you don't have on this original one did you mean to do that or are you just forgetting that this thing was referenced there and so and then most of the time like again I'm all about like really tight developer Loops like if I'm doing stuff I want feedback as fast as I can that's why I like an extension you may have seen when I'm doing things here if I do something that's not real uh am I prompt up oh my extension was running you know all these little context things and like you know you know most people by default you get your errors down the property bar there's an extension called error lens which I talk about in um the previous ones I know that's really hard to see but all my errors are right next to where the error is you know I'm just like I think it shows up on the namespace one when I had it like kind of half completed but you know I like to have my contacts like right there it's like if there's an error tell me right away I don't want to look at a thing I don't want to run a linter I don't want to do any of that stuff like like figure it out as fast as you can to help me fix my problems so that's all yet another long rambling preamble to if you type your variables in Powershell if you define a type then what that does is it locks that variable to that type so if you're writing a long script and you you say you know you know you know like my credential you know and you set that to if you lock that type then if later in the script you forgot you were you had already named it that credential and you try to assign it to you know something completely different it'll give you an error saying hey you tried to cat you tried to put a string in APS credential and that doesn't work whereas if you don't put that PS credential in front it'll happily let you reassign it just fine and completely break your script in a really weird to debug thing that takes you forever to figure out where the problem was but one other thing that's really nice about typing your variables if you type your variables you get all the intellisense for them so if you type that just like that now if I'm referencing this thing later I get all the if I intellisense I get all the properties right there I don't have to guess I have to go back and look at the variable to see what type it was I have to go out to the Powershell help to see what things are I don't have to run git member to then find out my things it's just right there you know that whole Loop of going to get member and finding the properties is just right there this works for any.net type but it's not just Powershell stuff sorry go ahead does it work uh yeah most of the time it should so if you do that uh maybe not okay it's because you're having to sign it so actually the type is still technically no but the thing is is that because Powershell is not statically typed it's still a runtime thing so the editor has to see what that variable is assigned it was assigned a null then it's going to be what goes to the Powershell completer thing is hey what things can complete null and the Powershell extension just kind of stares at you like what are you even doing here you know it's like dude do you not know how this works you know um it probably does I mean again all these completer apis like a lot of this stuff is just passed through into Powershell it's just a lot of stuff was broken or didn't exist so the only thing about ISC is that's locked to five one so any of the completers like the splatting stuff is never going to work in ISC because that's seven stuff um but I imagine a lot of like the basic stuff of like of like I'm not even going to say but that basic is not the right term for it like a lot of the typical stuff you would expect like parameter completion and even some of this type stuff if you define the type or if you have it as a runtime type yeah all that none of that's like super fixed in fact this is something I'm not showing something right now that's fixed this is actually just a preamble to the other stuff that I'm going to show because this is more like if you've never seen this before just be aware that like if you type a variable then you get really nice intellisense through the rest of your script so now that everybody's on board with that concept right so our credit equals our negative seeing that see now I can use my timeline view over here and just be like hey what changed here this is actually git but in my gutter it shows me just nice little indicators of like hey you added something here you change something here and I can click here and see exactly it's kind of hard with the small screen but I can click here and see okay this is exactly what I changed and what changed I took that thing and I edited it from that to that say Okay revert it you know fix my stupid mistake and now it's fixed so that now that doesn't use timeline that uses git so that was going back to my last git commit when I was testing this that is super useful like if you just want to experiment with something and you just hack away on it but you don't want to like revert your whole repository you don't want to figure out the git reset command line to get that one file you just go to that Gutter and it's also really good in like code or if you like were working on some code and you walk away from it because you had to go fix an emergency you come back three days later you're like what was I even doing here you know well you can go to the diff you can go to the thing or you can just go in the code and then just look for those little gutters again it's just little UI things that can make a huge difference in your productivity you want you to get used to using them like this you know I will never fault anybody for writing Powershell notepad if that works for you great but just like stuff like chat GPT and stuff like if you get an assignment I get an assignment and I have all these tools and co-pilot and little magic brushes and copile which I'll show you that just let me magically fix stuff like I'm gonna get this project done faster than you and then who's going to get promoted first you know so that's it it's just what it comes down to and now if you have no competition and that works for you that's fine like you know you know there's plenty of room for Cobalt programmers still you know but but like that's my philosophy My Philosophy is like you know as soon as I saw chat GPT I'm just like I gotta learn everything about this because like it was like as soon as VMware came out it's the first time I saw VMware like I have to learn this because I don't have a job in 10 years if I don't learn this as soon as I saw Cloud stuff really take off like AWS and Azure I'm like I need to drop VMware right now because I need to get into this stuff because it may not be 10 years it may not be 20 years but like if I want to be where the action is and I want to be where all the exciting stuff is I gotta get ahead of this now I didn't do that with crypto I didn't do that with nfts thankfully but you got to pick and choose sometimes but yeah so um so that's the whole concept of the idea of being able to do those kind of completions but now there's a lot of additional kinds of inferences that you can do so one thing that you can do is that if you set output type on a function you can specify the type and this is just this doesn't have to be like just Powershell types like I made that class earlier that dog class and so now that I have this function that's defined in my thing I'm just going to go ahead and run it just to make sure it's in here so now that output type is defined if I'm wherever I'm calling that function now I get Auto completion for the result of that function and the reason you have to do output type because in Powershell by default you can output anything like it's not strict on what you return and that output type is not strict it's not going to error if you output a string like it's it's it you're just basically offering a hint saying hey I wrote this function and you just have to trust me that what's going to come out of it is something of the dog class so but now it makes it so that again you can have that function be in a module that's somewhere completely different and you're using script you don't have to know how that thing was written but then when you do get dog before you even test it and run it when you get to your next step you can get the intellisense and already know what the properties are again without having to get member without having to do all that you're saving maybe you know maybe you're saving 30 seconds but if you save 30 seconds a thousand times that starts adding up to real chump change you know so then once you have that another nice thing is um you have the same kind of I demoed this earlier I jumped that so yeah so you can auto complete these but one thing is kind of neat is that you know you can you don't have to do the you don't have to know the very specific namespace you just have to kind of know what your type is so if I want to do something like PS credential PS grants is a bad example because it's got an autocomplete let me do like process so like you know these are all the.net types in my system like everything in.net that's loaded in my system whether it comes from modules whether it comes from what's built into Powershell whether it comes from what Powershell adds in every.net type autocompletes here and you notice that was pretty fast it used to be a lot slower the Patrick did a lot of great work speeding that up but what happens is when you go here like I don't have to know actually let's go back to my list example like I don't have to know this might not work because I have the yeah because I have it as a namespace let's see what's a better example let's do what are these specialized ones let's do concurrent bag there we go so I just know now I read somewhere that concurrent bag is something I should use but I don't know what library provides I don't know but I know it's built in so when I do this I select this concurrent bag once I select it it auto fills the rest of the name for me so you don't have to remember system collections concurrent you just know concurrent bag and you know and then like I don't remember the rest of that stuff just fill it in for me and you saw when I did list because I did the using namespace like if you do list here because I had the using namespace at the top it doesn't complete the rest of that because it knows that I already I told it already like I don't want all that junk just anything in this space I just want the short name so again another nice little thing speeds things up optimizes your your experience um one thing I do hope that we eventually get added is very similar to like how typescript and c-sharp work where like you can do a type like concurrent bag and have an option where if you hit enter here rather than put the whole thing out it will just put the short one and then put the using namespace at the top for you but that's how it works in typescript that's how it works in c-sharp it's super nice it's super convenient and I do believe there's a way we can make that work for Powershell too and have it as an option obviously not everybody wants that but it would be a really nice option um so um one other thing that's been fixed is positional parameters so what you can do is that um it used to be there used to be an issue like if you had different positional parameters like when you did these completions these completions usually come up in like if you have if you've written a script that has like you know I want this to be the first implied parameter I want this to be the second implied parameter this has been fixed so that if you specify those you can get to where you need to go and and um and and have it actually show the right correct next parameter or sometimes it would fail out at this point just a little thing um so getting back to the whole thing about types so one thing that commonly happens is that um when you do things like git process select object now at that point like the PS item again you look at that PSI item you're like what came out of this command what do I need to get member on this to find out what's in there and that kind of stuff so now there's inference for that so if you get processed and you do it to for each object select object where object any of those sort of built-in like iterative link style um uh commandlets now on the PS item you see it has all the properties of my process so I don't again I don't have to go look it up I don't do anything just as I'm writing whatever whatever type that is in this case you know it's a it's a process type so again I can change this from git process to get child item and then when I do my DOT I get child item properties so that works with select object wear object Etc really again saves you a little bit of time if you're not intimately familiar with it if you're working with an API you're working with a custom module you know you don't have to go look it up it's just it's just right there you might have to look up like what that property does but you know at least you're getting pretty much all the information you would get from git member just like right there um this is just a simple one this intellisense now works like if you have an attribute you can actually this intellisense would not work it now does work so have you ever tried that before and it broke it works now let's try it again um this one's kind of neat so if you have a PS custom object like you know you do a select object also all this stuff all if you hover over commands this has all been Rewritten it's going to get better than this too like we're hoping to get all like that get help and all that stuff in there but for now like you get all the different parameter sets of that command just by hovering over it that's really nice um but if you haven't if you have something and you take a variable and you um do like a select object on it and that just becomes a PS custom object but PS custom objects don't have types you know like it's a PS custom object like it it has types in the sense that is it is now technically like a new.net type but it's not as easy to infer as something like get child item well because we know what you selected now um this now works so that maybe it doesn't I gotta do the individual item on there [Music] yeah why is this not happy well I might be lying about this one but I had it working okay we'll chalk that one up to the demo Gods but typically what would work with this one would be is that if you did the select object through oh wait am I on seven I think this is a seven four one so I might be in the wrong version of Powershell no I'm on seven four okay I don't know this is a preview thing this will be in the next preview but um this is another one of those Mark I I like a lot of this I just went down that guy's crazy commits and I'm just like oh this works oh this works oh this will I'll just put all those in a file and show that to everybody um but this one basically the ways to work if you did the dollar X you should only see like name and path like because it can know that you selected name and path therefore name and path should be the only things on this thing um get random now passes through so that same thing but like if you have a get random in between um all the you know these are all get child item properties before this would break and like it wouldn't be able to know what your PS item was because you passed it to some other command that doesn't have an output type now it can infer that get random always outputs whatever same type came into it so that it can know that okay you know you passed a child item in so by reference get random can't change that it's always just going to Output child items back out so now this intellisense works um so if you do Powershell classes a lot and again my advice generally for Powershell classes they are awesome for data types they're awesome for structuring data making sure you know defining contracts so that when somebody sends you something or they're using your your thing and they need to send you an object that you can force them to use a certain type or otherwise it'll error out if um if uh I I don't recommend like you go crazy and try to treat them like c-sharp types like don't try to do tons of methods any of that kind of stuff you're just going to be in for a world of pain don't try to have classes inherit from other classes if you're going to do that at least put them all in a single file don't try to spread them out there's a whole there's a whole Powershell issue about base I call it the classes here there be dragons this year that lists all the problems with Powershell classes and it's there it's just because that they were never really designed they were designed to make DSC easier that's all that they were there for and they just have this nice side effect of being this really nice way to structure data sometimes so all that being said is my as my sort of like uh Preamble there's a nice new intellisense here too so if you have like a class grade Pyrenees and it inherits from dog that's what that colon means it's like I have dog now I have a new class Great Pyrenees that inherits from it if you make a Constructor for that The Constructor will inherit the prop will know the properties that came from that parent class so like if you're inheriting any class like if you're inheriting something out of the Base Library if you're inheriting something out of a closed source.net library that you don't have access to so you can't see the source code you now you don't have to again guess you don't have to get member you have to do some crazy Byzantine things like do a test Constructor just so that then you can get member on that object to find the properties you just do that and now you know what all the base properties are available in addition to whatever you defined on this like if if I added another property here that would be you know um I don't know fluffiness because he's a pretty Fluffy Boy if I had a property for fluffiness then fluffiness would be in this list in addition to the properties of the of the above class so really nice uh um with hash tables it didn't used to be able to infer the types of the things that are on them now it can so again same kind of pass-through before you do test items and then like it wouldn't know like what's in there now it now it'll pass through so that you can get your intellisense on whatever that property of the hash table was so even if each of your hash tables have different properties you go to different properties each one will give you different intellisense based on whatever whatever you assign to that property you don't even have to pre-type it beforehand as long as it's populated um this one's kind of nice if you use any kind of.net method Constructors which oh is there a record not my did I not get this in here yeah of course it's because I way up here this thing was supposed to be using namespace so here we go quick example it's like oh I forgot the other stuff so first of all co-pilot did this for me that's cheating but if I didn't have co-pilot I just start with system management drill space dot a control space and I just saved myself how much typing and how much time you know because I use the Intel sense it just goes much faster because now that I have that in there and technically I have to run it down here for it to show up now error record will work because again I do everything short otherwise this should be system or you can usually leave system off so and so this would have to be management automation error record but here because I did that using namespace it can just be our record so but now that it's here I can do a new and if I auto complete this now you get all the different Constructors that you can use for that.net type if you don't do a lot of.net type stuff every once in a while you have to run into this stuff everyone's all just something you can't do in Powershell but there's something in net that lets you do it and so if you ever use this new thing before like this was just a wild guess or you would type new without the parentheses hit enter in the command line look at it there but it's right here for you and so you don't have to guess and you have that available right there another thing that has been updated in vs code this drove me crazy for years you couldn't resize this dialog you now can you can stretch this thing however you want it used to be fixed so like if the stuff ran off the screen you're out of luck you know or if it was too tight tough tough stuff use an ultra wide yeah it's like we don't accommodate your your Ivory Tower status yeah um you mean you mean like pop it out so not really because um I don't see I I seen her I I never use that so but um I haven't ever done it like that um it's not possible to like have it as like I don't think it's possible to have it in like like the side pain like I don't think it's where like you do new and then it shows up over there I don't see any reason why it wouldn't technically be possible because the component can be moved to the webview it just hasn't been programmed to do that um yeah again that I'm sure somebody out out there watching this recording is screaming at me right now being like yeah you just changed this setting and it works fine but I don't know how to do it personally that's just not something I do much so yeah I can't answer that one sorry um yeah so that that's kind of the main run of completers and that took up a heck of a lot more time than I expected it to but because you guys ask such great questions all right uh let's see what else can we get to here in a little bit here so um well I think the last thing I'll do is just some of the neat debugging stuff that exists um so I'm a lot of the customization of like tuning and tweaking get all this stuff in um if you go watch those earlier videos that I talked about there's all kinds of stuff in there there actually is not that much new there's some neat new extensions there's a lot of that neat kind of stuff and we can talk about some of those maybe after the session if you want to know about them but for now I'm just going to show off some more of the debugging stuff so here's a sort of a simple debug script as an example so I have a script I just put in a couple Global a global here so you can see what that looks like a script variable so you can see what that looks like I have a function here get test and that function has sets a couple things and then invokes another function and that other function is down here it takes one parameter and it has another parameter that we don't set it's just implied and then returns that parameter so that makes sense what like it's just a simple function that calls another function and so anybody confused about like what this does should be pretty straightforward so we're going to go ahead and then way down the bottom I actually run the thing so the first thing I'm going to do is one thing that's really nice is anywhere that there's a variable in your code you can now right click it and just say add to watch and now it'll monitor that for you through the debug session whereas before you had to manually type it maybe type it with any of that kind of stuff now it you know you can do that with test parameters here too we'll just go down here and add to watch and now it's tracking it over there in my debug console this this stuff does not scale well to very high font typically this stuff is very small it's very easy to read so but you know bear with me here so then I have a few break points set um we'll go ahead actually I'm going to take the break points out for now so we're just going to go ahead and run this script for now just use using my fancy interactive my user settings so there's no Json in here so run ran the script Rand is fine if I expand my terminal up here it's probably showing the detail here clear yeah so it runs it and so I get that five that I set at the test here which then got set down here so one neat thing that we can do now is let's go ahead and break point to this point right right up to the point where right before output because like let's say I'm getting an output of seven I'm like why am I getting seven I understand so I do I set my break point I hit my run and it goes through there goes through git test go through invoke inner function and then gets in here and then ends up here so there's a couple neat things um you might not see this yellow stuff on your right this is one of the extensions that I covered in the past it's called inline variables written by Tyler who used to manage the vs code extension I don't know why this is not in the main extension it's just his extension works there's no reason to merge it but that's a great extension to get just lets you see what it's supposed to be but you'll notice this variables pane has changed a lot one thing is that there's all these different headers now so this is where I get to get the claim to fame this is this is the thing that drove me crazy I spent a whole bunch of time learning typescript learning C sharp two I wrote this so um I made this so that I really like this idea of Auto like in visual studio if you do see stuff C sharp stuff and I do very little C sharp stuff I'm getting a little bit better I really like this idea that like hey I want a section show me variables that are contextually appropriate to what I'm doing right now I don't want the dump and variable list and have to find what I want I just want the stuff that's like appropriate to my function so I came up with just some general logic of scope and that kind of stuff to try to figure out hey what's important to you so if I'm here at test parameter then obviously things I care about are my parameters that were coming in so there's test parameter and not set parameter and of course those watches that I said earlier they're set to where I had so I can see where I'm at where I'm screwing up all that kind of stuff but I also have all these other Scopes that exist so I can see all the variables that are part of my command so how many times have you ever done like you know you go in and you're debugging but then you try to do my invocation and it doesn't come back with anything it's because you're already past where that my invocation was uh defined but now we capture that so you can come in here and you can see you're my invocation and your PS bound parameters and see all that stuff without having to do it the command line or having to set a you know do a right host to see what it is like you can see what it was at the time and then you'll then you have your local scope so you know you have your Auto for like your most important stuff but like if you want to see the stuff that's in the local scope then like those script variables that I set you come down to script scope and you get all the fancy variables all the automatic variables and then of course in script down here is my script descript bar and because I set it to an object this stuff used to be really ugly I rewrote all this so that arrays look really nice now like you used to get all that all this stuff there's a little section down here for raw View this is what it used to look like and yeah like it's like is that really useful to you when you're debugging like how much of that stuff do you really care about yeah you don't care about that you care about what's the object and what's its properties and this works for hash tables works for any kind of object we got all that stuff fixed it was a massive pain for me to figure out because it's already complicated enough as it is but all that stuff now works as ends but but if you if for whatever reason your bug is so esoteric that you got to get into all this crazy detail it's still there under that raw View and then of course your globals and in my globals is uh my fun Global variable which is there so you have this nice like breakout so you can see like art is your thing being infected by another variable is it being overwritten you know were you expecting to grab a script variable but if you see it in local you realize oh I accidentally Define this variable in local and I wanted the one from script so now I got to go find where to find local and get it out of there it helps you solve all those really hard to find problems that aren't just going to come up with an easy parser of of you know you didn't assign this variable or you know this thing through an error it's that stuff where I wanted it to be five and it's seven but the script works so like okay how do I troubleshoot that like where do I even start so you just start by stepping through the code one other thing that's really nice here is that there's this call stack feature so in the call stack it shows like I said I I told you how it ran and you just kind of had to trust me but here you can see I would actually ran it started at the interactive session where I started the thing it started this little script block which is basically the way that we hook into it just it's basically just dot sourcing the the thing running and then the next thing it is it went to get test it went through git test until it got here and you see all the different colors the green is basically like hey this is where we left get test to get to where we are now and so now we're in invoke function and then the yellow is this is where we are now and of course you know the giant big yellow arrow also helps too but you can also see the line number over there um and so then we can go to our main function so we can see how we got here so this is really useful like if you're doing a loop or if you're working with some other code sometimes you get to a point or like or this is really good like if you get an error message you can search for the error message especially like if you're taking over uh somebody else's code like if you're taking over a co-worker's code and you get some error message you're like where did this error message come from you can just search for the error message in the code put the break point there and then run the same code and when you get to where that error message is you can see how you got there and then you can work you can work your way backwards and realize oh I see this was supposed to be this but he didn't put any kind of parameter validation on this thing and he let me type you know he let me type cookies when I was supposed to type you know dinosaur and that's why it doesn't work because he didn't let me not type cookies but one really nice thing about this is check this out if you look at the variables if I go back to git test I see the variables at the time it went into invoke my function so you can see this not you don't have to set a break point here and then step in you can automatically go back to where it was when it left that command and see the state where it is basically you're it's almost as if you're going back in time and leaving your break point here but without actually having to rerun the script and go there which is super nice and again none of that is like super magic in the code extension all that stuff actually happens in Powershell like if you look at the Powershell debugging code you know powershell's not three million lines of code for nothing I mean it's not all fat like there's a lot of very complex very well written out much smarter than me or at least much more anal retentive than I am to write all the code to capture all that stuff and all I had to do was figure out a way to tease it out and display it in vs code and that's what I did um so that that's kind of like the main aspects of the debugging in a nutshell but I really wanted to show those different views one last thing I want to show is this new thing that was added to vs code and again it's great because vs code is so written with the extensions and it uses all these standard apis is sometimes they add something and then we just get it for free because it just calls the apis that we already defined with a contract with the vs code extension sorry the vs code extension host which is where the vs code extension runs inside there's this whole long API of like contracts that they give us they say like hey you know if this thing happens you know we're going to call this function and then you can do whatever you want with that function just let us know we're just letting you know that hey this event happened inside vs code so there's this nice new feature another way I can do this is like say I don't want to see any break points today I want to do that I just want to check something what if I just want to right click this and I want to debug I want to run the script until I get to where my cursor is so if you click run my cursor it runs the script and it came right to where my cursor was I'd have to set up a debug and I'm doing that but this does it calls your default debug profile which in my case this was run file it just sets a break point basically in the background but it's a nice little UI thing where it's just like okay I did that okay I see how that happened but what if I want to be here okay so I have to set a breakpoint I have to go click run I just right click here run this you know run to cursor I want to see how I got there and now I'm there so that is I use this as soon as they introduce that feature I just saw it one day I'll just right click I'm like what the heck is this I'm like this is so cool and like and this that run to cursor Works in typescript Works in C sharp again because they all just use the same standard break points API like we didn't implement this they just they just made a fancy thing that does all the break pointing type stuff for you and because we wrote to the breakpoint interface well I didn't write Tyler did most of that um you know then it just works and that's one of the really great things about the whole vs code ecosystem and kind of what I want to close on is the great thing about vs code is it's just like Powershell in terms of philosophy the idea is that you take the time to learn the tool and they will do their best to make sure that's the best investment you've ever made because it's got a community around it that's passionate about it can't tell right um that you know wants to make it better has all the same frustrations you have and that they're like we want to enable those people who get frustrated just like I do it might be a hurdle the Powershell extension more than most because the power strip extension has to be extremely complicated just due to the nature of making it work like ISE um the uh but you know they Empower us to be able to contribute these things and make it so that everybody benefits and that's part of the spirit and philosophy of Open Source why Powershell is open source now why Powershell is such a wonderful module library that you know anything you can want to think when somebody thinks it up and they've had the same problem you have and they've taken the time to publish it and if you've had the problem and you want to publish it you have that there so if you believe in that philosophy and you believe in Powershell and open source um it's my opinion that vs code matches that same sacred promise and it's worth checking out so thank you very much and I wish you a good conference
Info
Channel: PowerShell.org
Views: 5,193
Rating: undefined out of 5
Keywords: powershell, windows powershell, techsession, powershell summit
Id: 1Tk8n47xiIA
Channel Id: undefined
Length: 92min 22sec (5542 seconds)
Published: Wed Jun 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.