In the fnADQuery() function change the line for error checking after $oRS = $oCMD.Execute to...

Code:

$oRS=$oCMD.Execute
If @ERROR Exit @ERROR EndIf
If $oRS.BOF AND $oRS.EOF Exit @ERROR EndIf



...and check the @error and @serror. My guess is that you are not using the correct ADsPath to the foreign domain.