What’s new in PowerShell 5.0 Preview for developers?

There’s some great information about the improvements to DSC, the new OneGet package manager and the like over on the Windows Server blog, but I am not going to repeat that here. As with most of these community technical previews (CTPs), they tend to only highlight the things they want the rest of us to poke at and assess, or the things they see as the most impactful. As they don’t really have the cycles to document the less impactful stuff, there are sometimes some hidden gems in there, so, with a decompiler, coffee and some custom tools to compare assemblies, let’s see what we can find. This analysis is based on examining System.Management.Automation only, comparing it to the 4.0 RTM version.

Debugging Jobs

Now, one of the more recent things to be added in v4 was remote debugging but there hasn’t been much said about it. Regardless, debugging remote jobs wasn’t a scenario it handled very well. That’s no longer an issue, it seems:


I did notice some quirky behaviour though. My test script writes to the output stream and when I exit the debugger with “exit,” I am still attached to the remote job and the output will continue to stream to the screen until I hit ctrl+c. It’s only then I am returned to the calling scope. Also, when you first attach, you can see that it will consume all of the output stream before dumping you at the interactive debugger.

Debugging Custom Jobs

Of course if you were paying attention, you’ll remember that v3 introduced the notion of custom jobs, by way of the JobSourceAdapter framework. Previously, the only kind of jobs we had were for handling events and for running scripts like the example above. The adapter extension point lets anyone use an external system as a source of “jobs” and optionally allow control of these via the standard job cmdlets, Start/Stop/Suspend/Resume/Remove-Job. Now, we can expose our own custom remote debuggers for our custom jobs:

    public interface IJobDebugger {
        bool IsAsync { get; set; }
        Debugger Debugger { get; }

This is possible because the Debugger class became abstract in v3 also.  Derive from this to facilitate your own remote custom job debugging.

AST Serialization

The other thing I noticed was that the entire AST (abstract syntax tree) graph lost the ability to be serialized: The SerialiableAttribute was removed. IIRC, there are some subtle bugs that can happen when you round-trip an AST via the serializer, bugs that were not noticed in v4 when it was enabled. I can’t for the life of me remember what they were, but if I find my notes, I’ll update this post. This ability was used internally to clone an AST graph quickly, but now that the graph has been rendered non-serializable, all AST instances gained a Copy() method instead.

About the author

Irish, PowerShell MVP, .NET/ASP.NET/SharePoint Developer, Budding Architect. Developer. Montrealer. Opinionated. Montreal, Quebec.

Month List

Page List