Dotneteers.net
All for .net, .net for all!

PowerShellStravaganza

I was strongly looking forward for Techstravaganza NYC - not just because it’s a New York bound conference, not just because the different tracks focusing on different materials (PowerShell, Windows, Exchange and Azure Cloud), but also because our very own Tome was (as always) one of the organizers and presenters. His session (Anarchists guide to PowerShell - What you’re mom told you not to do with PowerShell and how to do it!) not only won the competition on best title, but I think close to winning the best content award too.

From the 4 available tracks I went with PowerShell - mostly because my knowledge is the lacking there most. From the lineup of strong sessions I picked: “Anarchists guide to PowerShell - What you’re mom told you not to do with PowerShell and how to do it!” by Tome, “Rewriting history: extending and enhancing PowerShell features with fantastic results.” by Kirk Munro and a panel discussion featuring all of the days’ PowerShell speakers.

But not to run forward too much, for me the day was kicked off by Kirk’s rewriting history session. Next to learning where PowerShell’s builtin capabilities trail off and when you need to start touching compiled cmdlets (like proper parameter usage, deriving commands, proxy cmdlets, performance!) we should not forget that PowerShell is now cross platform and opensource - if someone wants to add one of the extensions, they are usually should feel free to do that using github, PRs, etc. To write such a custom cmdlet, you only need your favorite editor (Sapien, VS2017, VSCode - your choice), the Microsoft.PowerShell.*.ReferenceAssemblies for the matching PowerShell version, and some patience :) So with PowerShell 6 just in alpha, being cross platform, what is the better time to learn writing cmdlets than now?

One of the first magic we seen and resonated with me was about something eerily similar to https://github.com/nvbn/thefuck (if you are not aware of that tool, it adds missing sudos, it adds missing --set-upstream to your git command, tries to find out what command you mistyped, and like 50 more - see https://github.com/nvbn/thefuck/blob/master/README.md#how-it-works for details). Using some lesser known command-not-found-handling extension point, it enabled nice shorthands to replace “verb -verbs” constructs with “verb-verb” constructs, and much more.

The next item that caught my attention was LanguagePX - a demonstration of ExcelPX by building a DSL that enabled moving from:

Get-Process | Export-Excel -Path "$([Environment]::GetFolderPath('MyDocuments'))\test.xlsx" -Force -Show -AutoFitColumns -IncludePivotTable -IncludePivotChart -PivotRows Name -PivotData WorkingSet64

 

to:

ExcelDocMagic "$([Environment]::GetFolderPath('MyDocuments'))\test.xlsx" {

    Properties {

        Overwrite = $true

        Show = $true

        AutoSize = $true

    }

    PivotData {

        RowPropertyName = 'Name'

        RowAggregateValue = 'WorkingSet64'

        IncludeChart = $true

    }

}

 

Turns out this not only caught my eyes - this is on the way to become part of PowerShell 6 to support custom DSL languages thanks to an RFC. This way the option to achieve something that would have been crazy idea before, like generating a Visio document an object oriented way and have PowerShell fill out the data there, all with proper type safety - I’m sold.

Next to tackling capability to fix mistakes and provide nice syntactic sugars, next to provide a way to define DSLs, the 3rd item that surprised me from Kirk was HistoryPX - providing an extended set of history information AND last output support in PowerShell. Not only does it capture output, exception criterias, command duration, but also the number of returned objects! Makes it so much easier to work with history. Add to this the $__ variable capturing last output, with configuration when it should be captured - e.g. I can say I don’t want sort operation to be captured if I don’t want to.

As part of the sponsorship section, I seen Sapien’s IDE for the nth time - but this was actually the first time I spotted the fact that there is support for a splatting refactor in the context menu. Now, how did I live without it??

The next interesting tidbit was coming from Stephen Owen - before his session I was not that much involved (let me rephrase: I had absolutely no overview nor details) in the Enterprise Mobility Management suite’s integration with VMWare AirWatch and PowerShell, but he showed some interesting tidbits on how these component work toghether: either AirWatch sends command to EAS to authenticate, and with the established secure trusted relationship AirWatch can send cmdlets to PowerShell in accordance with the email policies (and it gets executed) (this does not require a server per se), or using the AirWatch Enterprise Integration Service to deliver the PowerShell commands to the server. It was eye opening to see PowerShell used together with VMWare – not two tech/companies I’d put in the same sentence otherwise.

Then came the session I was waiting for since the morning: the anarchist guide on how not to use PowerShell with Tome. Starting with the nice library of ShowUI which enables you to *easily* build graphical user interfaces using PowerShell scripts – to the level of using ‘New-Button -Content "Hello World" -Show’ or:

$User = [ordered]@{

   FirstName = "John"

   LastName = "Doe"

   BirthDate = [DateTime]

   UserName = "JDoe"

}

 

Get-Input $User -Show

Next demo was about Azure Functions, PowerShell – with removing the comma between them – small powershell snippets you can use in a serverless scenario provided by Azure Functions to provide stateless microservices. And if microservices, we saw a way using Apache Zookeeper to spin up PowerShell worker processes on incoming data feeds – think about like a distributed zookeeper powershell cluster. And this was the best place I think for a Treadmill shoutout J

And the thing we (I?) weren’t really prepared for - http://www.leeholmes.com/projects/ps_html5/Invoke-PSHtml5.ps1 - I’ll leave you to try it out. And the list continued – a very interesting demo of using Unity (the 3D game engine) and PowerShell together to display data (some of them on a spinning globe) using PSUnity, another crazy language experiment by allowing to write native .NET IL in PowerShell using PSILAsm

The list is endless :)

 

 

 


Posted May 05 2017, 05:52 PM by petersm

Add a Comment

(required)  
(optional)
(required)  
Remember Me?