Private/Search-ADforSID.ps1

function Search-ADForSID {
    Param(
        [string]$SearchRoot,
        [string]$Filter,
        [string]$LogPath
    )

    try {
        $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
        $objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry($SearchRoot)
        $objSearcher.PageSize = 1000
        $objSearcher.Filter = $Filter
        $objSearcher.SearchScope = "Subtree"

        $results = $objSearcher.FindAll()

        if ($results.Count -gt 0) {
            $User = $results[0].GetDirectoryEntry()
            return $User.samaccountname
        } else {
            return $false
        }
    } catch {
        Write-Log -Message "Error searching in $SearchRoot : $_" -LogPath $LogPath
        return $false
    }
}