I don't think hyphens(-) need to be escaped. What do you get if you run

Code:
  
break on

? getOU(@wksta)

function getOU($computer)
dim $objRootDSE,$strDomain,$objConnection
dim $objCommand,$objRecordSet,$dn

$getOU = "Not Found"
$objRootDSE = GetObject("LDAP://RootDSE")
$strDomain = $objRootDSE.Get("DefaultNamingContext")
$objConnection = CreateObject("ADODB.Connection")
$objConnection.Open("Provider=ADsDSOObject;")
$objCommand = CreateObject("ADODB.Command")
$objCommand.ActiveConnection = $objConnection
$objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://" + $strDomain +
"' WHERE objectCategory='computer' and cn='" + $computer + "'"
$objRecordSet = $objCommand.Execute()
While Not $objRecordSet.EOF
$dn = $objRecordSet.Fields("distinguishedName").Value
$getOU = right($dn, len($dn) - instr($dn, ","))
$objRecordSet.MoveNext
loop
endfunction