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.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
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.
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.
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 $_ }
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.