Find out in which version a PowerShell Cmdlet was introduced

Some days ago Thomas Rayner (whom I admire for his passion and consistency when it comes to sharing his knowledge) posted about the same topic on his blog. He mentioned a method on how to utilize GitHub in order to find out the earliest Version a PowerShell Cmdlet was introduced. When I read the Thomas’s post, I couldn’t resist thinking about an option to automate the process. My first attempt was to check whether the information is already part of the help system or could be retrieved using Get-Command (using ‘Expand-Archive’ as an example):

Get-Command Expand-Archive | Format-List * | Out-String -Stream | 
     Where-Object {$_ -like '*version*'}
Get-Help Expand-Archive -Full | fl * | Out-String -Stream | 
     Where-Object {$_ -like '*version*'}

While both commands return some information in relation to a version, in general, there is nothing telling us about the PowerShell version the Cmdlet was first introduced.
The next thought I had, looking at Get-Help was the online version.

Get-Help Expand-Archive -Online

This command opens the default browser opening the HelpURI, which in this case looked like See the last part of the URI? There seemed to be some hope following this route. The webpage features a drop-down where users can select a PowerShell version (3-6). Selecting Version 3 from the drop-down for the Expand-Archive help page brought me to this URI Version 4 revealed a similar result, while the Version 5 URI did not contain the “viewFallback…” part. Similarly, when pasting a URI like into the browser’s address bar, it redirects automatically to the “viewFallback…” version. Great, there we have it, a pattern that can be automated :-):

  1. Construct the base help URI for a Cmdlet
  2. Loop through the PowerShell version in ascending order (3-6)
    1. Add the version part to the URI
    2. Invoke the web-request and capture the redirect target
    3. If the redirect target URI does not contain the “viewFallBack…” part.
      • We found the first PSVersion where the Cmdlet was introduced. Return the version
    4. Otherwise continue the loop until we find the first version, where the redirect target URI does not contain the “viewFallback…” part.

Here you go “Get-FirstPSVersion”:


Photo Credit: sharkbait via Compfight cc


I'd love to hear what you think

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s