Find the Mode Value
# Get the number of occurrences for each number $numberCount = $NumberArray | Group-Object | Sort-Object -Descending count # check that it is possble to calculate a mode if(@($numberCount | Select-Object Count -Unique).Count -gt 1){ # Get the count for the numbers with the most occurrences $topCount = ($numberCount | Select-Object -First 1).Count # Get the most frequently occurring values...
Find the Median Value
# sort array $NumberArray = $NumberArray | Sort-Object if ($NumberArray.count%2) { # if odd $medianvalue = $NumberArray[[math]::Floor($NumberArray.count/2)] } else { # if even $MedianValue = ($NumberArray[$NumberArray.Count/2],$NumberArray[$NumberArray.count/2-1] | Measure-Object -Average).average } $MedianValue
Single object array
[System.Collections.ArrayList] $ArrStrings = @() $ArrStrings.Add("string") | Out-Null
Standard PowerShell Object Array
[System.Collections.Generic.List[PSObject]] $arr = @() $arr.Add($objectA) $arr.Add($objectB)
Reverse a string
$array = $string.ToCharArray() [array]::Reverse($array) -join($array)
Convert date to string with specific format
[datetime]$date = Get-Date $date.ToString('yyyy-MM-dd')
Convert number to string with leading zeroes
[int]$int = 7 $int.ToString('000')
Convert number to string with certain number of decimals
[double]$pi = 22/7 $pi.ToString('0.00')