This one should appeal to both the statistically inclined of you, as well as those interested in cryptography. Measure-Frequency will take any array (or string) and give you the frequency distribution of it’s contents.


function Measure-Frequency {
Get the frequency distribution of a set.
This function will get the frequency distribution of a set (array) of data.
It supports array types, as well as strings.
Measure-Frequency $array
Measure-Frequency $string -CaseSensitive
Author: Øyvind Kallstad
Date: 10.02.2016
Version: 1.0
param (
[Parameter(Mandatory = $true, Position = 0)]
[switch] $CaseSensitive
try {
if ($InputObject.GetType().Name -eq 'String') {
if ($CaseSensitive) {
$inputArray = $InputObject.ToCharArray()
else {
$inputArray = $InputObject.ToLower().ToCharArray()
else {
$inputArray = $InputObject
$inputArray | Group-Object | Sort-Object Descending Property Count | ForEach-Object {
$frequency = $_.Count / $inputArray.Length
$percent = '{0:P0}' -f $frequency
Write-Output ([PSCustomObject] [Ordered] @{
Value = $_.Name
Count = $_.Count
Percent = $percent
Frequency = $frequency
catch {
Write-Warning $_.Exception.Message

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s