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

    # anything that begins with https:// is hypothetically ok
    # we're not going to actually query the directory here
    if ($DirectoryUrl -like 'https://*') {
        return $true
    }

    # anything else must exist in our WellKnownDirs object
    if ($script:WellKnownDirs.ContainsKey($DirectoryUrl)) {
        return $true
    }

    # otherwise, fail
    if ($ThrowOnFail) {
        throw "$_ is invalid. Must be $($script:WellKnownDirs.Keys -join ',') or a full https:// URL."
    } else {
        return $false
    }
}