 Hi, welcome to Visual Studio Toolbox. I'm your host Robert Green and joining me today from Madison, Wisconsin is Adam Driscoll. Hey, Adam. Hey, how's it going? Good. And we are using the magical technology of Skype so that Adam could be in the show without having to fly all the way out here to Redmond. Yeah, works great. Adam is the creator and author of the PowerShell Tools for Visual Studio. This is now the third version of it, I believe. Or is it the fourth? I've kind of been working on it for years probably since Visual Studio 2012. OK, so about the third version. Third version. A huge number of downloads, more than 300,000 downloads, very popular, very successful. And so today I thought you could show us what are the PowerShell Tools? Who are they for? What can you do with them? Why'd you invent them? Sure. Give us a demo. Yeah, sounds great. So I guess just to start off, the PowerShell Tools are a set of extensions for Visual Studio that enable you to debug PowerShell code and kind of author it in the full experience that you get with Visual Studio, including IntelliSense, debugging, single stepping, test explorer window, and access to a project system inside Visual Studio. So I built it because I saw the gap there. I was actually writing a lot of PowerShell scripts and I was primarily a C-sharp developer. So I spent a lot of time in Visual Studio and there was really no PowerShell support when I first cracked it open. So what kinds of things, why were you writing a lot of PowerShell scripts? I was working for a company that we were actually developing a PowerShell module. So I was doing the actual C-sharp development for that module. But to test it, we would have to kind of jump out of Visual Studio to run those scripts. So I decided I was going to build the tool myself. So there is a PowerShell editor, which is a very colorful text editor. But through your extension, you get all the benefits of editing and debugging in Visual Studio is what you're saying. Yeah, exactly. All right, cool. Yeah, so I can share my screen and kind of show you where to get this and just give a little demo of how to use it. So if you are looking for the PowerShell tools, there's a couple ways you can get it. First of all, you can go through Visual Studio and actually use the extension and updates view to look for it in here. Just search PowerShell and you should find it right away. And then also, you can go onto the gallery page. It's a great place to grab it outside Visual Studio. It'll download the V6 and install it to your current version of Visual Studio. It actually supports 2012, 2013, and 2015 right now. And the other way that you can actually install this is through the Visual Studio installer. So you can actually check a checkbox and it'll actually go out and download the latest V6 into Visual Studio during your installation process. You can get it right off the bed, yep. So you're saying I already have it installed because when I install Visual Studio, I just click Select All, so I already have it. Yep, exactly. Cool. So I actually worked with a team of Microsoft to kind of get that integrated. And the other way you can actually install it is if you open a PS1 file in Visual Studio, it'll pop a little ribbon down at the top to ask you if you want to install the tools so you kind of get a better experience. Nice. So yeah. So like I said, some of the features are kind of outlined on this page. I've been doing a decent job of updating the release notes and stuff here. The other place that I direct you to, if you do have any questions, concerns, comments, is the GitHub page. This is where people usually report issues or submit pull requests. So it's all open source. You can access that and contribute if you want to. So that brings up an interesting side question. So if I use this and I have questions, there's a Q&A on the gallery page, but then I can also come to the GitHub page. Do you have a preference? Do you look at one more than the other? I definitely look at the GitHub page a lot more. I don't have any notifications coming from the other one. So GitHub is the way to do it, I'd say. Got it. Yeah. Cool. So we can actually pop into Visual Studio and just kind of take a look at the tool if you'd like. I actually have Visual Studio open here with a PowerShell project. So just like any other project in Visual Studio, you have a project system for PowerShell scripts. There's a couple of different project templates that you can use. I have a module project template that automatically adds tests and a module manifest. And then a script template that adds just a PS1 file, that kind of thing. This is actually one of my other modules that I open source. It's just a P invoke module that lets you execute Win32API commands. But you can see that I've kind of organized it in this project system. And just like any other Visual Studio project, you can click through and open files and edit them, that kind of thing. A lot of people really like the PowerShell tools because being in Visual Studio, you automatically get source control for free. So you can see all this stuff is checked into GitHub right now. And you can see the status that everything is currently committed. And none of them actually have any changes. So we like pop into one of these commands or these files. You can see that this is a PowerShell manifest file, so a PSM1 file. Some things that you'll notice that you should see in any kind of language inside Visual Studio is that we have syntax highlighting. We have code collapsing on functions and comments. We have a dropdown here for finding and jumping between different functions that are defined inside your module or script file. So that should work on anything. Do you have go to definition and peak definition and refactoring and all that? And do you have to write that all yourself if you want it? I could. Because you don't get any of that for free, right? Right. So I'd have to write all that myself. One interesting project that is going on right now is PowerShell Editor Services. So there's actually a guy in Microsoft that's been working on the Visual Studio Code support for PowerShell. And out of that, he's actually open sourced a library called PowerShell Editor Services. And the idea is that anybody implementing an editor could take advantage of those editor services and then use them to do this kind of stuff. So kind of the future of PowerShell tools would be to utilize those editor services because they do provide things like that, like go to definition and find all references and that kind of stuff. So right now, this is kind of a homebrewed implementation of a PowerShell editor. But in the future, hopefully, you can consolidate that with the VS Code one, too. And what about Rosalind-type support, so light bulbs and code analyzers and all that? Is that also something that has some of that done by hand? But a lot of the Rosalind stuff isn't going to work just because PowerShell can actually build on top of Rosalind. So we'd have to really implement that kind of stuff. I know there are some asks for some of that, especially around refactoring and the peak definition stuff. I know that in the last three minutes of talking, we've come up with two years' worth of work. Yeah, exactly. So let's focus on what's in the tools now. All right, so just like any editor, like I said, is all this functionality that really isn't there when you first open Visual Studio. In addition to the main code editor window, which you get things like IntelliSense and Depletion and that kind of thing. Cool. You also have access to some other windows that I've implemented. One really nice one is the PowerShell interactive window. So it's just a PowerShell prompt inside Visual Studio. This is where all the output goes and as well as the output window. So it kind of goes in both places. But the nice thing with the PowerShell interactive window is that you can actually do the same thing that you can do in any PowerShell prompt and run commands. Cool. You also have access to the DTE object. So if you've ever worked with any kind of automation inside Visual Studio, you can actually write scripts that automate Visual Studio. So you can see I can grab the active document and things like the full name of that document. So the DTE is like the com-based wrapper around the Visual Studio automation framework. So you could write scripts that automate Visual Studio using something like this. Very cool. On the left-hand side here, you'll see that I have a test explorer window. There's actually a test adapter that's developed that will find Pester tests. So Pester is the unit testing framework for PowerShell. It's kind of written in the BDD syntax where you have described context and it blocks for describing how you are testing a particular piece of functionality. And then what's gonna happen is the adapter window is gonna find each one of the described blocks and then list them out here so that you can right-click and run them just like you could with a C-sharp test or something like that. In this case, the test is passing. In addition to that, you have debugging features. So if I click F5, you're gonna see here is I've set a break point inside my test. It's about to call this function and you have access to all the things you'd expect in debugging. So I have access to the call stack. You can see that since I'm running it through Pester, the call stack is actually kind of big because it's going down through the Pester module and you can double-click on those places and jump to different source files. Additionally, you have access to the locals window. So these are all your locally defined variables at this point in time and you can expand those and break down things just like any like .NET objects sort of thing. Single-stepping is also part of this so you can step through your code as it evaluates and debug things as you see fit. So yeah, and then all output like I said goes out to the output window. So now you can see that this particular test passed after running for 44 seconds because I was talking through that. But that is kind of like a high-level overview of what's currently in the PowerShell tools. So it's kind of like basic language support integrated into Visual Studio for PowerShell. So there's a lot of things that are kind of asks that have been almost complete like form support. There's actually a Windows Forms Designer in some beta versions of Visual Studio tools that I have. That allows you to create Windows Forms with a drag and drop editor and then it generates PowerShell code that actually will generate that form on the fly. So you can just have a PS1 script generate that kind of stuff. So you would do that for having UI in your PowerShell scripts? Right, we have a lot of administrators sometimes or the developer of a PowerShell script is sometimes an administrator that he's gonna hand off this script to some sort of just technical support kind of person. And rather than having them run the script, they'll put like a little UI on it to like check a couple buttons, that kind of thing. So it's good for that. So that's an amazing example of something that supported WinForms, something modern that supported WinForms first. Yeah, right. That's excellent. Well, the thing with PowerShell and XAML is that there's really not too much plumbing that you need to do. You can hook up the XAML Designer inside Visual Studio and then just have the PowerShell kind of compile the XAML on the fly and do all the binding and stuff. So there's actually a lot less involved in that than there was with the Windows Forms and the implementation. Cool. Yeah. Yeah, so that's kind of a run through of the PowerShell tools for Visual Studio. Like you said, it's got a lot of downloads and I'm currently working with the team to make sure that it works on the next version of Visual Studio so that we can make sure that this continues to be a really popular extension and people really like it. And I encourage everyone to go out and report issues and I'm always open to contribution. So anybody that wants to help out letting somebody's features or fixing some bugs, I'm always willing to take pull requests that kind of thing. Yeah, it's on GitHub, it's open source as you said. Now, so for somebody who's been doing a lot of PowerShell development and already knows PowerShell and is also in Visual Studio, it's great to be able to do this in Visual Studio and get the benefits. If you find yourself as a Visual Studio guy who now needs to start doing PowerShell, what would you recommend a good place for people to learn how to do PowerShell? I would start with PowerShell.org. It's kind of a group of the PowerShell MEPs kind of got that started and it's a great resource. They have all kinds of blog posts and links to some free books that are available out there to learn PowerShell. So that is probably where I would start because it's great jumping off point. So what are some of the things that you're working on feature-wise for the next version of this? What are like the top two or three things that are being asked for? The big thing is gonna be PowerShell Azure Services because it implements a lot of the stuff that people are asking for in terms of going to definition and finding all references, that kind of thing. So that's gonna take a really big refactor on my part, so that's kind of my main focus over the next couple of months. Aside from the next version of Visual Studio Support. So historically, Visual Studio Support really hasn't been too difficult to implement. It usually just works, but we need to do some testing and probably fix a couple of bugs around that. Sure, all right. Cool, well thanks for coming on and showing us this. This is very, very cool stuff. Yeah, thanks for having me. All right, we will see you next time on Visual Studio Toolbox.