Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

More Improvements to my Test-WSMan Replacement

Posted on June 3, 2016June 8, 2016

Recently I shared a replacement function I wrote for Test-WSMan. That version addressed some of the shortcomings in the original command, at least for me. After using it for a bit I realized I wanted a few additional changes so I now have version 2. The new version now supports multiple computer names. I also replaced the ProductVersion property with separate properties for the OS, Service Pack and Stack numbers.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

image

I used regular expressions to parse the original property.

#parse the product version line into separate properties
[regex]$rx = "OS:\s(?\S+)\sSP:\s(?\d\.\d)\sStack:\s(?\d\.\d)"
$pv = $test.productVersion
        
[string]$os = ($rx.Matches($pv)).foreach({$_.groups["OS"].value})

#force these as strings and later treat them as [decimal]
[string]$sp = ($rx.Matches($pv)).foreach({$_.groups["SP"].value})
[string]$stack = ($rx.Matches($pv)).foreach({$_.groups["Stack"].value})

TheĀ  final output drops the ProductVersion property in favor of these properties. This makes it easier to filter out older computers.

image

I've updated the help with a few other examples. The new version is still on GitHub as a gist.

I'll update code there as necessary. I'm having other thoughts about error handling so there might be some minor changes in the future. I have also not tested this against anything other than a Windows server. The whole point of WSMan is that it is a standard protocol that other platforms can use. I'd love for someone to test this against non-Windows devices and report your findings in the comments on GitHub.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

2 thoughts on “More Improvements to my Test-WSMan Replacement”

  1. Christopher Blodgett says:
    June 8, 2016 at 2:08 pm

    Curious question why not just pipe a foreach into test-wsman. I like a lot of the validation and testing. Just an interesting use case and reasoning.

    Example of a possible easier solution:
    $arraylist | %{ test-wsman $_ }

    1. Jeffery Hicks says:
      June 8, 2016 at 2:41 pm

      Of course you can do that. For me the issue was as much as using the output from Test-WSman as piping things to it.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d