Quick Counts In Powershell

Chrissy LeMaire has a quick pair of one-liners for counting occurrences in Powershell:

I always forget how to do this, and Aleksandar Nikolić posted a really beautiful answer on Powershell.com

For a file:

-split (Get-Content .\test.txt | Out-String) | Where-Object { $_ -eq "test" } | Measure-Object | Select-Object -exp count

That was easy.  Check out the article to see how to do this with a string.

Related Posts

What’s In Your Powershell Profile?

Shane O’Neill wants to know what’s in your Powershell profile: This brings me back to the main point. My profile does 3 things Changes the default colour of error and warning messages, Sets an alias for notepad to “n” since I use it so much Set-Alias -Name n -Value notepad , and loads up the dbatools prompt […]

Read More

Policing Database Deployments

Drew Furgiuele has a rather interesting library that he’s released to the general public: The base return is the TSQLFragment object, which in turn has a Batches object, which in turn holds… well it can hold a lot of different things. When the text is parsed, it will determine what type of object to return based […]

Read More

Categories

May 2016
MTWTFSS
« Apr Jun »
 1
2345678
9101112131415
16171819202122
23242526272829
3031