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.

Memory Reporting with PowerShell

I’ve started a new project and I’m hoping a few of you will give it a spin and let me know how it works for you. I’ve created a PowerShell module called MemoryTools that uses a few WMI classes and performance counters to provide insight into memory utilization and configuration on your servers. The module has several commands including one that skips the pipeline (exception to the rule!) and uses Write-Host to display memory status in living color.

show-memoryusage

The project is up on GitHub at https://github.com/jdhitsolutions/MemoryTools if you’d like to give it a try. The Readme file should give you a overview of what to expect. Use GitHub to report any bugs or feature requests. I know I still need to add command help.

The module should work on any computer running v3 or later. Note that the Get-PhysicalMemory command, which queries the Win32_PhysicalMemory class, may not show results for some properties. There are a few new class properties that require Windows Server 2016 but I decided to include them anyway.

I look forward to hearing about your experiences.

Finding Git Repositories with PowerShell

As part of my ongoing improvement process this year I am starting to use Git much more. Yesterday I posted an article with my PowerShell script to create a new project folder which includes creating a Git repository. My challenge has been that I don’t always remember what I have set up with Git and what I have not. So I put together a little PowerShell function to identify folders with Git repositories.

The function, Find-GitRepository, takes a top-level path as a parameter. The function then searches all sub folders searching for hidden directories called .git. For each directory, the function creates a custom object that includes the path and details about the Git repository. To get those values the command jumps to each folder where I parse the results of git branch and git log.

find git repositories with PowerShell

There’s probably a bit more information I could pull with Git but for now this seems to be enough for me. You can find the function as a gist in my Github repository.

As with my previous script, I assume you have the git command line tools in your path.  If you use Git I hope you’ll try it out and let me know what you think.

Advice, solutions, tips and more for the lonely Windows administrator with too much to do and not enough time.