Functions/Select-SoundexString.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function Select-SoundexString {
    <#
        .SYNOPSIS
            Perform soundex string matching.
        .DESCRIPTION
            This function lets you perform string matching using
            the soundex algorithm. Note that this is only useful
            for shorter strings.
        .EXAMPLE
            Select-SoundexString -Search $searchQuery -In $searchData
        .EXAMPLE
            $searchData | Select-SoundexString $searchQuery
        .INPUTS
            System.String
            System.String[]
        .OUTPUTS
            System.String
        .NOTES
            Author: Øyvind Kallstad
            Date: 08.07.2016
            Version: 1.0
        .LINK
            https://communary.wordpress.com/
            https://github.com/gravejester/Communary.PASM
    #>

    [CmdletBinding()]
    param (
        # The search query.
        [Parameter(Position = 0)]
        [ValidateNotNullOrEmpty()]
        [string] $Search,

        # The data you want to search through.
        [Parameter(Position = 1, ValueFromPipeline = $true)]
        [ValidateNotNullOrEmpty()]
        [Alias('In')]
        [string] $Data
    )

    PROCESS {
        foreach ($string in $Data) {
            if (Compare-Soundex $string $Search) {
                Write-Output $string
            }
        }
    }
}