Friday Fun: A Better Test-WsMan

I saw a question on Facebook about how to get Test-WsMan to return a simple Boolean result. The Test-Connection cmdlet has a -Quiet parameter that makes this possible. But Test-Wsman does not.  Certainly, you could script a comparable outcome. Here’s one way:

Or, if all you want is to simply filter a list of names you could use an expression like this:

The only names that come out the end will be those that responded to Test-WsMan. Or you can go another way and create your own version of Test-WsMan which is what I did.

I used my Copy-Command script to create a wrapper function I named Test-MyWsMan.  I added a parameter called -Quiet so that the command behaves like Test-Connection.  While I was at it, I also addressed some other shortcomings (for me at least) in Test-WsMan. When testing multiple computers, not having a computername property meant the results weren’t that useful. And you could only get values in the ProductVersion property if you specified an Authentication parameter value. So I fixed these “issues”.

You can find my new command on as a gist in GitHub.

I’ve also updated help and examples. Now, I have a more useful tool.

image

Now, I can filter like this:

image

Or even on the ProductVersion.

“chi-hvr2″,”chi-dc01″,”chi-dc02″,”chi-p50″,”chi-dc04” |
where { (Test-MyWsman -ComputerName $_).ProductVersion -notmatch “Stack: 2.0” } |
foreach  { Get-CimInstance win32_operatingsystem -computername $_}

image

I can already see where it might be helpful to split up that ProductVersion property into separate properties. But I’ll save that for another day.

In the meantime, I hope you’ll grab a copy and let me know what you think. Enjoy your weekend, especially in the US where we have a long one.

UPDATE: I’ve published v2 on GitHub and briefly explained it at http://bit.ly/1ZjusCr. The code you see listed above may not completely match this article.

4 thoughts on “Friday Fun: A Better Test-WsMan

    • Thanks. Although technically, this is not a proxy function. But I could have used my Copy-Command script to create one and make similar adjustments.

Comments are closed.