Private/Test-ValidDnsPlugin.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 Test-ValidDnsPlugin {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory,Position=0)]
        [string[]]$PluginName,
        [switch]$ThrowOnFail
    )

    $pluginDir = Join-Path $MyInvocation.MyCommand.Module.ModuleBase 'DnsPlugins'

    $PluginName | ForEach-Object {
        # check for a file with the matching name in the DnsPlugins folder
        $pluginFile = Join-Path $pluginDir "$_.ps1"
        if (!(Test-Path $pluginFile)) {
            if ($ThrowOnFail) {
                throw "$_ plugin not found at $pluginFile"
            } else {
                return $false
            }
        }
    }

    return $true
}