Originally Posted By: Glyn
When running the vartype it comes back as a decimal does this help?


Depends. You were expecting a string, yesno? Decimal's probably not good then. Which variable did you VarTypeName()?

More importantly you have:
 Code:
$oRS = $oCmd.Execute


But you don't check the success of the command. You have assumed that it has worked and you then go on to reference the properties.

If the query failed then you will get unexpected results.

Check what is coming back in $Tempname *very* carefully and see what might cause problems, if it doesn't exactly match the AD record you are going to have problems.

Be especially careful of special characters. For example if a name contains leading / trailing spaces then it won't match, and if it contains a single quote such as "O'Leary" then it will actually break the query.

Other problem characters are "\" which is used to escape characters such as the "," in some query types (LDAP mainly).