Private/Find-FromFilter.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
Function Find-FromFilter {
    [CmdletBinding()]
    Param (
    [parameter(Mandatory = $true)]
    $Data,
    [parameter(Mandatory = $true)]
    [String]$Parameter,
    [parameter(Mandatory = $true)]
    $Filter
    )

    Process {
        Write-Debug -Message "[$($MyInvocation.MyCommand)] Executing function"

        Foreach ($F in $Filter) {
            Write-Debug -Message "[$($MyInvocation.MyCommand)] Filtering result(s) on parameter $Parameter with value $F"
            $Result = $Data | Where-Object {$_."$Parameter" -like $F}
            Write-Debug -Message "[$($MyInvocation.MyCommand)] Found $($Result.Count) item(s)"

            $Result
        }
    }
}