DEV Community

Kevin Hulquest
Kevin Hulquest

Posted on

2 1

Standing on the Shoulders of Giants

I've always had an affinity for the Windows development platform. In the past I've written a plugin for SQLServer Management Studio and some PowerShell cmdlets for a storage platform. My main work has always been predominantly writing Java and Python.

Recently I had an opportunity to use my corporate Windows 10 laptop more often. Since I read all of the rave reviews about Visual Studio Code, I thought I'd reawaken my Windows development environment.

Just like any skill we acquire, if we don't use it and keep the skills sharp, then the skills become dull. But just like muscle memory, our brains quickly remember the skills that were once second nature. I have this relationship with PowerShell. I'll never be able to get over the lack of Vim keybindings but I'm always pleasantly (re)surprised at the capabilities of PowerShell. It truly blows the doors off text-based shells. Sorry Linux.

Part of my current reawakening led me to a new technique that I wanted to share with you all. The problem I faced was "I know I have a function defined to do this but I wonder what the code is behind the function?" Then I stumbled across Get-Content function:FunctionName. While this is cool, it is really just a way to remember about code that I've written in the past. The technique becomes much more powerful when it's pointed to the content written by pros.

A simple demonstration of this lay with New-Guid. Let's take a look at the result when we run Get-Content function:New-Guid.

PS [hci-monitor] > Get-Content Function:\New-Guid

    [CmdletBinding(HelpURI='https://go.microsoft.com/fwlink/?LinkId=526920')]
        [OutputType([System.Guid])]
    Param()

    Begin
    {
        [Guid]::NewGuid()
    }

As you see, this is a bit of C# that implements the Cmdlet interface. It has a pointer to documentation and arguably a (small formatting) bug since the OutputType decorator is indented too far. The function simply returns a new Guid object. I don't think the Linux folks really appreciate that this Guid isn't the text you want but a full fledged object you can forward, associate and (of course) get a text representation.

This is just a simple example. Have a look at something more complicated like Update-IscsiTargetPortal. Now you can inspect this code to get a better idea about how the pro's at Microsoft accomplish a non-trivial task. This is how you sharpen your PowerShell skills and stand on the shoulders of giants.

Until next time...

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (1)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay