2

Comparing commands between PowerShell versions

In the article Decoding PowerShell build numbers, I stated the need to have some form of reference to what the various PowerShell build numbers means:PSVersionCompare_01

As stated in that article, due to the new and fast moving pace Microsoft have gotten into, we will see more frequent updates to PowerShell than before. Version number is one element, another one which is not easy to keep track of as a regular PowerShell user is what commands are new or changed. For example, parameters might be added or removed from existing cmdlets.

At the time of this writing, a new technical preview of Windows Server 2016 has just been released. But how can you know what is changed with regards to PowerShell commands?

There are some code snippets available to compare changes between versions. For example, Shay Levy’s script listed in this article. Since the need to perform this task will occur more and more often going forward, I decided to turn this into a reusable function. The function is named Compare-PSVersionCommand and is available in the module PSVersionCompare. You can either get it directly from GitHub, or use PowerShellGet to install it from the PowerShell Gallery: Install-Module -Name PSVersionCompare

In the initial version, Compare-PSVersionCommand have two parameter sets which makes it possible to compare based on either XML-files pre-gathered from systems, or data gathered directly via PowerShell remoting:

#Input gathered via PowerShell remoting
Compare-PSVersionCommand -SourceVersionComputerName HPV-VM-2016TP4 -CompareVersionComputerName HPV-JR-2016TP5 -ModuleFilter Microsoft.*

#Input from XML
$PSCommandDataRoot = 'C:\Program Files\WindowsPowerShell\Modules\PSVersionCompare\PSCommandData'
$SourceVersionPath = Join-Path -Path $PSCommandDataRoot -ChildPath 'Microsoft Windows Server 2016 Datacenter Technical Preview 4_5.0.10586.0_Desktop.xml'
$CompareVersionPath = Join-Path -Path $PSCommandDataRoot -ChildPath 'Microsoft Windows Server 2016 Datacenter Technical Preview 5_5.1.14284.1000_Desktop.xml'
Compare-PSVersionCommand -SourceVersionPath $SourceVersionPath  -CompareVersionPath $CompareVersionPath -ModuleFilter Microsoft.*

Here is an example which shows the differences in the native PowerShell modules between Windows Server 2016 Technical Preview 4 and Technical Preview 5:

PSVersionCompare_02

Showing changes for all commands in all modules is impractical in an article like this, so a .txt file containing all changes is available here.

Same information for Windows Server 2016 Nano TP4->TP5 (TXT-file), using PowerShell remoting as input:

PSVersionCompare_03

The XML files specified are generated by running the following on systems running the versions you want to compare:

Get-PSVersionCommand -ComputerName HPV-JR-2016TP5 -Export -Verbose
 

If you run Get-PSVersionCommand without -Export, you will get all commands from system wide modules returned.
As you might know, there is a new $PSEdition variable (also exists in $PSVersionTable.PSEdition) introduced in the Windows Server 2016 Technical Previews. This is intended to distinguish PowerShell Core (used in Nano Server) from “regular PowerShell” called PowerShell Desktop. If -Path is not specified to Get-PSVersionCommand -Export, the default naming convention for the generated XML-file is “OS Caption_PSVersion_PSEdition.xml” (for example Microsoft Windows Server 2016 Datacenter Technical Preview 5_5.1.14284.1000_Core.xml).

When creating reference XML-files for server operating systems, I like to make sure that all Remote Server Administration Tools (RSAT) is installed on the reference computers in order to have all modules available for comparison. This can be accomplished like this:

Get-WindowsFeature -Name *RSAT* | Where-Object Installed -eq $false | Install-WindowsFeature
 

There are a lot more features planned for this module, so check out the Git repository for the latest status (or run Update-Module -Name PSVersionCompare if you already installed it using PowerShellGet). Some of the planned features:

  • A Name parameter for specifying what command to compare. If not specified, all commands will be compared.
  • Options for output- formats, such as CSV, JSON, and HTML. Default output format is meant for interactive usage, not to export.
  • An Online parameter for retrieving the XML files for the specified PS Versions from an online location. Defaults to the PSCommandData folder in the Git repository.

Although using PowerShell remoting for ad-hoc checking between two systems might be the most common scenario for using Compare-PSVersionCommand, the use of XML files should not be underestimated. If the community contributes with files to the PSCommandData folder in the Git-repository, over time we can gather a lot of information about commands in the different PowerShell versions making it easy to do comparisons without access to a system running a specific version.

Filed in: Articles

2 Responses to "Comparing commands between PowerShell versions"

Leave a Reply

Submit Comment

© 2017 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: