Digging into PowerShell Direct

Available in Windows 10 and the Windows Server 2016 Technical Preview, there is a new feature of PowerShell and Hyper-V that enables you to connect to guest machines that lack network access: PowerShell Direct. The standard PSSession cmdlets along with Invoke-Command now offer a VMID and VMName parameter. Simply run any of these commands as you normally would with a remote machine and you have access to a remoting session to the guest. It worked perfectly for me.


After playing with it a bit, I was curious to find out just how it works. The first place I looked was in the guest where there is a new service installed called the “Hyper-V VM Session Service” (vmicvmsession). It’s initially stopped but when I attempted to connect via Enter-PSSession from the host machine, the service was automatically started.

On the client end, I popped open .NET Reflector and dug into the Enter-PSSession cmdlet. This cmdlet can be found in the System.Management.Automation.dll. This is where you will see the new properties for VMName and VMID.


When a VM name or ID is specified, a new HyperVSocketConnectionInfo class is used rather than the typical WSManConnectionInfo class.


There were a bunch of interesting classes associated with Hyper-V remoting. They implement the glue necessary to open the connection and allow the PowerShell remoting proctol to go over the Hyper-V socket.


One class that is interesting is the RemoteSessionHyperVSocketClient class. It’s responsible for initiating the socket connection to the guest. In the constructor to the client, it instantiates a HyperVSocketEndPoint to pass to the Socket constructor.


Interesting to note is the protocol type is listed as ICMP and the socket family is a 0x22 magic number. Looking at the AddressFamily enumeration, this address family is not listed. Also, the address family is not registered with IANA. The endpoint’s serialized value is a combination of the address family, VMID and service ID. The service ID depends on whether or not this is the first connection to the guest.


On the first connection, the first step is to send the username and domain name.


Next a string is sent to indicate whether or not a password will be sent and then the password is sent. Afterwards, the client checks for a failure string.


Once this socket is open, standard PS Remoting protocols seem to be used just as you would with a WSMan connection.

Overall, it’s a super handy feature and it’s interesting to see how it’s being accomplished. I do wonder what the magical address family 0x22 will be called or if it will remain 0x22.



Upcoming features in PowerShell Tools for Visual Studio

Long time no blog! I wanted to showcase a couple neat features coming to PowerShell Tools for Visual Studio. My hope is that we can get some feedback before pushing to the gallery for the world to enjoy.

Windows Forms Support for PowerShell

The Windows Form designer is handy for throwing together some drag and drop UI. I spent some time futzing with creating a CodeDOM provider for PowerShell. The Windows Form designer talks CodeDOM so we need to translate the PowerShell AST into a CodeDOM format in order to get the form designer to understand a PowerShell script. The other half of the equation is taking an existing CodeDOM and translating it into a functioning PowerShell script. Some of the challenges were that, until recently, PowerShell didn’t support classes so we had to fake it. Right now the CodeDOM provider is targeting PowerShell v3+. It uses the AST to create CodeDOM CompileUnits.

Once you have the latest build installed, you will have access to a new item template (need a new icon!).


Adding a new file of this type will create two files on disk. One is the designer code. The other is the event handling and execution file. The designer file contains all the code to render the UI and hook up the event handlers found in the other file. The execution file invokes the designer code and then shows the UI.





The designer file shouldn’t be edited by hand. The form designer is using the PoshTools CodeDOM provider to generate that on the fly.

Double clicking the form in the Solution Explorer window will show an error. Still trying to nail this one down!


To fix the error, just add references to System.Drawing and System.Windows.Forms.

From there you should be able to drag and drop items from the Toolbox on the form. Adjusting the properties should work. You can also hook up event handlers by doing actions like double clicking on buttons.

Would love to hear feedback! I need to fix the issue with the references before this will be committed to the main branch.

PowerShell Command Explorer

One of the neat tools in the PowerShell ISE is the command browser. It allows you to view different modules and the module within them. It also allows you to select different parameters and sets, view help and execute commands. Well thanks to Erwin de Vreugd, we now have that functionality within PoshTools!

After installing the updated build, you can access the Command Explorer by naviation to View->Other Windows->PowerShell Command Explorer. It provides very similar functionality to what is in the PowerShell ISE. This feature is looking very complete and will be merged into the main branch in a couple days. Check it out below!

Please play and provide feedback.

PowerShell Tools for Visual Studio – What’s new?

What’s been going on?

Over the past couple of months I’ve been working with an awesome team of developers and project managers over at Microsoft to bring some great new features and fix a lot of bugs in PowerShell Tools for Visual Studio. The first pull request from the Microsoft PoshTools fork was pretty large.



They’ve been very busy opening and closing issues as well.


x64-Bit Support

The most significant feature that was introduced is x64-Bit support. As you may be aware, Visual Studio is a 32-bit process and will be for the foreseable future. Before this release, the PowerShell runspace was hosted inside the DevEnv.exe process. This lead to the inability to use 64-bit modules or PowerShell features. Once DSC was released and became popular, it was pretty important to implement this functionality. The team at Microsoft developed an out-of-process PowerShell host that now starts up with Visual Studio when PoshTools is installed. All the IntelliSense, debugging and classification services utilize WCF to communicate with the host process. DSC, Workflow and 64-bit modules, like SharePoint, are now supported in PoshTools. It also means better support can be built for cross-language debugging between .NET and PowerShell. This was something that was impossible when the host was maintained within DevEnv but, with a little work, could be achieved with the new architecture.


Configurations no longer show red squiggles!

Remote Session Support

Additionally, the PowerShell host now supports remote sessions. You can enter a PSSession with Enter-PSSession or by using the icon located in the REPL window.




New Look and Feel

The default syntax highlighting has been updated to match the ISE. You can always update your syntax highlighting as you see fit by using the Fonts and Colors dialog in the Options window of Visual Studio.


We’ve also introduced all new icons developed by the UX team at Microsoft. Much better than what I was drawing in paint. 😉


Finally, we reorganized the project properties dialog to be easier to work with. All the same options are available but on different pages.



Visual Studio 2015 CTP6 and Windows 10 TP Support – No more VS2012 Support

We made some changes to the extension manifest to allow for installation into VS2015 and Windows 10 preview builds. The extension continues to work in previously supported configurations, aside from VS2012. With VS2015 in the near future, it was decided to drop support for VS2012. We would love to hear feedback as to whether or not this is a big deal for the community going forward.

Compatibility with Python Tools for Visual Studio

A lot of the code that for the project system and the entire REPL were direct ports of code found in Python Tools for Visual Studio. Because of this, some GUIDs were reused and would cause problems when both extensions were installed. This has been cleaned up and now both extensions should live in harmony together.

TONS of bug fixes

There were fixes ranging from breakpoints only being hit once to scripts that were slow to type in due to the function drop down list. We’ve done some work to hit the most impactful issues and hope that you can see a more refined extension as a result. There are still open issues that we are tracking but will continue to work to knock that number down. Please don’t hestitate to open issues of your own.

Happy PowerShelling!

I encourage you to go out and try out latest beta build. We hope to gather some feedback on the new features and experience before publishing to the Visual Studio Gallery. Please feel free to submit issues or even pull requests.


PowerShell Tools for Visual Studio – Now 100% more free!

UPDATE: Just download the Visual Studio 2013 Communtiy edition and PoshTools works perfectly with it!

Recently, the Python Tools for Visual Studio team released support for Visual Studio Express 2013. After emailing the team, I found that there is a white list of extensions that are allowed to be installed in Express. Unfortunately, this is an internal Microsoft process and not available to external developers. Although this was a bummer, they pointed me once again towards the Visual Studio Isolated and Integrated Shell. I had previously experimented with the Isolated Shell with little luck and didn’t pursue it until a nudge from the PyTools team. Rather than having to create an entire Isolated Shell environment, you can instead download and install the Integrated Shell. It provides the entry point to launch the components provided by the Isolated Shell. It certainly was confusing to me but I gave it a shot. Success! You can download and install both the Isolated and Integrated Shells and then install PowerShell Tools for Visual Studio. 100% free!

Installation Steps

1. Download and Install the Isolated Shell
2. Download and Install the Integrated Shell
3. Open Extensions and Updates…
4. Install PowerShell Tools for Visual Studio

Black magic:


So far, it looks like there are a couple features that aren’t working quite correctly.

– Debugging doesn’t seem to work as expected. This really limits the functionality and I’ll be looking into it.
– No built in source control integration. This sucks but is just a limitation of Isolated Shell. There are extensions for Git and SVN available on the gallery.

Otherwise, things stuff as IntelliSense, REPL, Syntax Highlighting and the project system seem to be behaving.

Feel free to try it out and look forward to updates in the near future.

PowerShell Tools – v0.8.0 – Now with REPL!

Today, I’m announcing the release of PowerShell Tools for Visual Studio v0.8.0. There are some important installation changes in this version and I want to make sure people are aware. You can download the latest on the Gallery (2012\2013) or via GitHub.

Installation Changes – Important!

The extension has been broken into two different editions based on Visual Studio version. This was done to fix installation issues caused by how the extension was being built. Building a different version for each version of Visual Studio has corrected this. For Visual Studio 2012 users, you’ll need to uninstall your current version of the extension and install the new version. Installing them side by side will cause issues. This should be the only time you’ll have to do something like this.

REPL Window 

This version adds an interactive REPL window. The REPL window is based on the same REPL that is integrated with the Python and Node tools for Visual Studio. You can run commands just like you would in any other PowerShell command window. You can access the window via View->Other Windows->PowerShell Debug Interactive. Output from your PowerShell scripts now goes to this window rather than the Output pane.


Minor Bug Fixes and Changes

  • Fixed test discovery
  • Removed Project property pages because they were not actually functional
  • Added $DTE variable for StudioShell support and automation accessibility

PowerShell Tools for Visual Studio Thanksgiving Special!

In celebration of the Thanksgiving holiday (and because I finished a bunch of cool stuff), I’ve released a healthy update to PowerShell Tools for Visual Studio to the Gallery! There have been a lot of enhancements to the extension. I’ll highlight some of the key features in this post.

Unit Test Adapter

This particular feature I’m pretty excited about. It exposes Pester support to enable authoring of PowerShell-based unit tests that are discoverable and executable via the Test Explorer window. The adapter picks up on Describe blocks and allows you to execute them as a set or individually. When a test fails, the stacktrace and error message are presented in Test Explorer. This should also allow you to run your unit tests during CI builds in TFS. Pester support requires Pester to be installed on the module path. PoshTools does not include it at this time.



Data Tips and Watch Window 

One feature I love in Visual Studio is the ability to hover over a variable and see it’s value. The newest version of PoshTools now has this functionality! It supports arrays and hashtables (unlike some of the interim GitHub releases). It expands multiple levels; just like other managed languages.



In addition to hovering, you can specify variables in the watch window. Handy!



Dark Theme Support

The last time I promised dark theme support, it was a lie (like the cake). I had implemented it incorrectly. This version now correctly supports the dark theme. If you are still having problems with the dark theme after an upgrade, make sure to reset your colors to default for the dark theme. The colors for the dark theme aren’t as vibrant as they were (if it worked for you) but they correctly change when themes are switched. You can still update your own colors for the theme.




I’ve also added support for Read-Host. You’ll get this handy dandy input box to specify anything you desire!


As always, this release is available on both GitHub and the Visual Studio Gallery.


Execution Policy in PowerShell Tools for Visual Studio

I’ve had several people report issues with PowerShell Tools for Visual Studio behaving differently than the NuGet console. After some investigation, I’ve found that NuGet actually resets the process scoped execution policy to RemoteSigned if it is not Unrestricted, RemoteSigned or Bypass.

This is taken from the NuGet source for the VSConsole.

      private static void SetupExecutionPolicy(RunspaceDispatcher runspace)
            ExecutionPolicy policy = runspace.GetEffectiveExecutionPolicy();
            if (policy != ExecutionPolicy.Unrestricted &&
                policy != ExecutionPolicy.RemoteSigned &&
                policy != ExecutionPolicy.Bypass)
                ExecutionPolicy machinePolicy = runspace.GetExecutionPolicy(ExecutionPolicyScope.MachinePolicy);
                ExecutionPolicy userPolicy = runspace.GetExecutionPolicy(ExecutionPolicyScope.UserPolicy);
                if (machinePolicy == ExecutionPolicy.Undefined && userPolicy == ExecutionPolicy.Undefined)
                    runspace.SetExecutionPolicy(ExecutionPolicy.RemoteSigned, ExecutionPolicyScope.Process);

My question is whether the community thinks this would be ideal for PowerShell Tools for Visual Studio as well. Currently, PoshTools is behaving like the ISE rather than NuGet. What do you think? Leave a comment or shoot me an email.

PowerShell Tools for Visual Studio Beta v0.5

If you haven’t seen the news, PowerShell Tools for Visual Studio is now available on the Visual Studio Gallery! The first beta brings with it many enhancements from alphas past and supports VS2013 RC. Here’s a quick overview of  the current state of the extension.


The current requirements for PoshTools are PowereShell v3 and Visual Studio 2012 or 2013RC. Several people have asked for VS2010 support and I’m researching the necessary changes. Also, there is a lot of interest in supporting VS2013 Isolated Shell. If the extension could be released in this manner it would make it completely free; just like the Python Tools for Visual Studio.

Editor Extensions

The extension adds language support to the Visual Studio editor. Some of the most important features are syntax highlighting, IntelliSense and code folding. IntelliSense with help you complete cmdlets and functions, variables and parameters. Code folding can collapse script blocks and comment blocks. Overall, syntax highlighting should be very similar to the ISE but there are known issues.


In addition to the basic functionality described above, the extension also adds support for the function navigation drop down bars on the top of editors. Using the v3 AST PowerShell API, I was able to discover the functions defined within the current file and present the navigation bars seen at the top of the editor window.

Function Navigation Drop Down

A big next step for the editor is snippet support but extensions do not support this; making it a bit tricky to implement. If you have a particular function you’d like you see in the editor, head over to GitHub.

Debugger Extensions

On top of the big changes to the editor there have also been some big changes to the debugger. The goal was the surpass the ISE in terms of debugging functionality. To accomplish this, I added support for the locals, break point and call stack windows.

The locals window shows all the variables in the current scope and enables the user to expand complex objects to dig down into the object. Just like when debugging other .NET languages, type information is provided. Next on the plate for the locals window is the ability to modify values at runtime. In addition to locals window support, I’m also looking at adding Watch window support.

Locals Window

Another key window when debugging is the break point window. It displays all current pending breakpoints that are set within all the open projects. Like any other break point, the file name and line number are provided. There is no support for conditional break points but would be a good feature to add in the future.

Breakpoints Window

Another important debugging window that is supported by PoshTools is the Call Stack window. Using the Get-PSCallStack cmdlet, the extension can display the current call stack when stepping or breaking in the debugger. There is currently no support for moving call stack frames and interrogating session state.

Call Stack Window

Finally, like with PowerGUI VSX, there is a project system dedicated to PowerShell. It’s been discussed to add different types of project systems for modules or generic collections of scripts but this isn’t currently the case. The extension exposes a project system that recognizes PSM1, PSD1 and PS1 files. In the current beta there is no support for automatic signing or manifest creation. There are dialogs created for this purpose but the MSBuild tasks and targets aren’t yet hooked into the project system.


Project System

I’d love to hear feedback about the current status of the extension. If you are trying it out please leave a review on the Gallery or enter any issues on GitHub.




The Future of PowerGUI VSX

PowerGUI VSX was released in June of 2010. Since then, it has received over 80,000 downloads between the Visual Studio Gallery and CodePlex. Over the past year, I have let the project slip. The last few versions didn’t even really add any new features but merely updated the version of PowerGUI they were compatible with. I’ve had a lot of requests for people to help out but haven’t seen any significant development on the project. One of the reasons this happened is that I knew I could do better. By embedding the PowerGUI editor directly in Visual Studio it caused a multitude of problems because it really wasn’t a true language integration but more like a hack.

Today, I’m highlighting a project that I’ve been working on and off for the last couple months. In the last week or so, I’ve dedicated some serious time to getting more parity between the current version of PowerGUI VSX and next major version. PowerGUI VSX v2 will offer true Visual Studio language support for PowerShell. It uses the Visual Studio editor and the raw PowerShell debugger, tokenizer and completion engine. Currently, the requirement is PowerShell v3 and Visual Studio 2012. This requirement may change depending on community support and adoption.

A lot of code has been taken from the current implementation of PowerGUI VSX. The project system remains the same. The skeleton for the debugging engine was harvested.

Finally, all the code can be found on GitHub. It offers a much better solution to social coding than CodePlex does. Check out the dev branch and fork me to add your own features.


Currently Implemented Features

Script Editor


Syntax Highlighting


Customizable Fonts and Colors



Breakpoint Support


Locals Support


Call Stack Support



Project System


PowerShell Project Template


Project Properties

PoshInternals – Multi Desktop Support

One really neat SysInternals tool is Desktops. It allows for managing several virtual workspaces, know as desktops on Windows machines. Unlike Linux that offers a builtin way to transfer between desktops, Windows does not natively expose a way to do so. The cmdlets added to PoshInternals now allow you to manage these virtual desktops right from the command line!

About Desktops

Desktops are little sandboxes of windows. Processes can be associated with a desktop and all windows drawn by that process will show up in that desktop. This allows you to declutter you main desktop into many desktops. Desktops are named entities and you can switch between them pretty easily once they are created. Simply creating a desktop doesn’t associate any processes with it. If you were to switch to a desktop without starting a process in it, you will see a blank screen. If you find yourself in this circumstance, you can access task manager and start processes that way.


Creates new desktops that are tied to the current Window Station. In most circumstances, this will be WinSta0 or the default Window Station. Window Stations contain one or more desktops and manage things such as the clipboard. For more information on Window Stations, check out MSDN. Desktops are limited by the desktop heap which, by default, is 48MB. By default, this cmdlet will start the explorer.exe process in the newly created desktop.


Returns the desktops that are associated with the current WinStation. The returned desktops are named and have a handle that is used to create processes in the desktop or show the desktop.


Activates the specified desktop as an interactive desktop. Again, it’s worth noting that if nothing was started in this desktop before showing it, you’ll have to use task manager to launch a process to work with in the desktop.

Start-Process Proxy Function

This proxy function adds the Desktop parameter to Start-Process. As expected, specifying the name of the target desktop will start the process in that desktop. One caveat with this method is that since PowerShell is a console application, if you just run PowerShell it will associate with the other desktop but input will still be taken on the current PowerShell window. This is due to how shared consoles work in Windows. To get around this and make a new PowerShell window, you can use the following command line.

Start-Process PowerShell -ArgumentList “& `”Start PowerShell`”” -Desktop Desktop2

Desktops is currently available in the dev branch of PoshInternals on GitHub. Check it out!

Here’s a video of it in action.

Interesting Side Note About Windows 8 and CreateDesktop

While creating the New-Desktop cmdlet I ran into an issue with Windows 8. Apparently, there currently exists a bug that will cause a BSOD from user mode code using CreateDesktop. I reproduced this on several Windows 8 machines with 100% consistency. The 5th parameter to CreateDesktop is the access mask used to specify security and access writes for the newly created desktop. I had a bug in my P\Invoke C# code that effectively was causing me to pass a $null as the access mask. This caused a BSOD everytime! It’s a little scary because it this function doesn’t require the process to be elevated. If anyone from Microsoft is curious at looking at the crash dump, here’s the analyze -v from WinDbg. I’ve also posted a simple example on PoshCode.