Soldato
- Joined
- 30 Sep 2005
- Posts
- 16,681
Guys I'm really struggling here.
Created a piece of code about two years ago which has been working fine. It does a whole load of checking before creating user accounts in AD.
Now we have some new user accounts starting with an M which for some unknown reason to me is not working with my code
objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://dc=domain,dc=co,dc=uk' WHERE objectCategory='user' " & "AND sAMAccountName=" & arrMain(i)(0)
Set objRecordSet = objCommand.Execute
Set objUser = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName").Value)
wscript.echo "name is " & objUser.displayName
The variable arrMain(i)(0) is what contains the users username. If the contents is for example 123456 everything is ok. However if it's M23456 then the code doesn't work. The contents of objuser or any fields from the objrecordset is always empty.
So lets say the variable is populated from a text file which looks like this which are user accounts:
123456
365221
M23456
267621
M7678221
478978932
on each iteration the code works, but always fails on the accounts which start with M. If I check to see the value of arrMain(i)(0) it is always ok and does contain the M accounts when they loop round.
The issue is when it loops to an M account and in effect runs this command, the command must fail, but why?
objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://dc=domain,dc=co,dc=uk' WHERE objectCategory='user' " & "AND sAMAccountName=M000482"
Created a piece of code about two years ago which has been working fine. It does a whole load of checking before creating user accounts in AD.
Now we have some new user accounts starting with an M which for some unknown reason to me is not working with my code
objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://dc=domain,dc=co,dc=uk' WHERE objectCategory='user' " & "AND sAMAccountName=" & arrMain(i)(0)
Set objRecordSet = objCommand.Execute
Set objUser = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName").Value)
wscript.echo "name is " & objUser.displayName
The variable arrMain(i)(0) is what contains the users username. If the contents is for example 123456 everything is ok. However if it's M23456 then the code doesn't work. The contents of objuser or any fields from the objrecordset is always empty.
So lets say the variable is populated from a text file which looks like this which are user accounts:
123456
365221
M23456
267621
M7678221
478978932
on each iteration the code works, but always fails on the accounts which start with M. If I check to see the value of arrMain(i)(0) it is always ok and does contain the M accounts when they loop round.
The issue is when it loops to an M account and in effect runs this command, the command must fail, but why?
objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://dc=domain,dc=co,dc=uk' WHERE objectCategory='user' " & "AND sAMAccountName=M000482"