|
|
|||||||
Hi all, working on a script to add users details in the Active Directory. what this script does it pulls the details from our oracle server like user name, first name, lastname and the script should modify the active directory. The problem is that the varible is not being picked up on $test, however if you look at my script you will see this bit of code ? $test which display the number fine, but not when you try to insert it into the script. Code: ;region Script Settings ;<ScriptSettings xmlns="http://tempuri.org/ScriptSettings.xsd"> ; <ScriptPackager> ; <process>kix32.exe</process> ; <arguments /> ; <extractdir>%TEMP%</extractdir> ; <files /> ; <usedefaulticon>true</usedefaulticon> ; <showinsystray>false</showinsystray> ; <altcreds>false</altcreds> ; <efs>true</efs> ; <ntfs>true</ntfs> ; <local>false</local> ; <abortonfail>true</abortonfail> ; <product /> ; <version>1.0.0.1</version> ; <versionstring /> ; <comments /> ; <includeinterpreter>false</includeinterpreter> ; <forcecomregistration>false</forcecomregistration> ; <consolemode>false</consolemode> ; <EnableChangelog>false</EnableChangelog> ; <AutoBackup>false</AutoBackup> ; <snapinforce>false</snapinforce> ; <snapinshowprogress>false</snapinshowprogress> ; <snapinautoadd>0</snapinautoadd> ; <snapinpermanentpath /> ; </ScriptPackager> ;</ScriptSettings> ;endregion Break on Function fn_LDAP() Dim $selectedProperties, $propertynames, $oCn, $oCmd, $oRS, $i $selectedProperties = "ADsPath" $propertynames = Split($selectedProperties, ",") $oCn = CreateObject("ADODB.Connection") $oCmd = CreateObject("ADODB.Command") $oCn.Provider = "ADsDSOObject" $ = $oCn.Open("Active Directory Provider", "", "", -1) $oCmd.ActiveConnection = $oCn $oCmd.Properties("Page Size").Value = 1000 $oCmd.Properties("Searchscope").Value = 2 ;ADS_SCOPE_SUBTREE ? $test $oCmd.CommandText = "SELECT " + $selectedProperties + " FROM 'LDAP://server.co.uk' WHERE objectCategory='user' AND cn = '$test' ORDER BY Name" $oRS = $oCmd.Execute While Not $oRS.EOF $obj = GetObject($oRS.Fields($propertynames[0])) ;$obj.Put("cn", "VALUE") ; $obj.SetInfo $obj.Put("displayName", "TESTVALUE") $obj.SetInfo $oRS.MoveNext Loop EndFunction Function fn_ODBC() Dim $cn, $cmd, $rs, $cnstring, $cmdtext $cnstring = 'Provider=MSDAORA;Password=password;User ID=id;Data Source=server;Persist Security Info=True;' $cmdtext = "SELECT DISTINCT PEOPLE.PERSON_CODE, PEOPLE.FORENAME, PEOPLE.SURNAME, PEOPLE_UNITS.UNIT_INSTANCE_CODE, PEOPLE_UNITS.CALOCC_CODE FROM PEOPLE INNER Join PEOPLE_UNITS ON PEOPLE.PERSON_CODE = PEOPLE_UNITS.PERSON_CODE and PEOPLE_UNITS.UNIT_TYPE = 'R' and PEOPLE_UNITS.CALOCC_CODE = '09' and length(PEOPLE_UNITS.UNIT_INSTANCE_CODE) = '6' " $cn = CreateObject("adodb.connection") $cmd = CreateObject("adodb.command") $cn.connectionstring = $cnstring $cn.Open $cmd.activeconnection = $cn $cmd.commandtext = $cmdtext $rs = CreateObject("adodb.recordset") $rs.cursortype = 3 $rs.locktype = 3 $rs.Open($cmd) While Not $rs.EOF And Not $rs.BOF ? "PERSON_CODE: " + $rs.Fields.Item("PERSON_CODE").Value ? "FORENAME: " + $rs.Fields.Item("FORENAME").Value ? "SURNAME: " + $rs.Fields.Item("SURNAME").Value ? "YEAR: " + $rs.Fields.Item("CALOCC_CODE").Value ? "GROUP: " + $rs.Fields.Item("UNIT_INSTANCE_CODE").Value ? "PERSON_CODE: " + $rs.Fields.Item("CODE").Value ? " " $test = $rs.Fields.Item("PERSON_CODE").Value $rs.Close $cn.Close EndFunction fn_ODBC() fn_LDAP() fn_QUIT() Function fn_quit() Quit EndFunction However if I do the following the program works. $test = 123456 the statement above will find the varible text and modify the AD account. It would be great if someone can help me out. Glyn |
||||||||
|
|
|||||||
I also added thios command ? $oCmd.CommandText to see what the output was like, and below is the output, and as you can see the cn'' has no number inside the brackets ' AND cn='' ORDER BY Name://student.server.co.uk' WHERE objectCategory='user |
||||||||
|
|
|||||||
This looks like a script generated with ASE (Admin Script Editor). Thanks, Kent |
||||||||
|
|
|||||||
o.k. need some help here I have posted below a basic script to update AD. The problem here is that the name I'm trying to update has a apostrophe in the name. and I think this is what is causeing the script not work. I think it fails during the LDAP lookup However no errors are displayed in the script. Code: Dim $selectedProperties, $propertynames, $oCn, $oCmd, $oRS, $i $selectedProperties = "ADsPath" $propertynames = Split($selectedProperties,",") $FN = '1' $SN = '2' $oCn = CreateObject("ADODB.Connection") $oCmd = CreateObject("ADODB.Command") $oCn.Provider = "ADsDSOObject" $ = $oCn.Open("Active Directory Provider", "", "", -1) $oCmd.ActiveConnection = $oCn $oCmd.Properties("Page Size").Value = 1000 $oCmd.Properties("Searchscope").Value = 2 ;ADS_SCOPE_SUBTREE $oCmd.CommandText = "SELECT " + $selectedProperties + " FROM 'LDAP://Student.carshalton.ac.uk' WHERE objectCategory='user' AND description = 'A'me Down' ORDER BY Name" $oRS = $oCmd.Execute While Not $oRS.EOF $obj = GetObject($oRS.Fields($propertynames[0])) $obj.Put("givenName", "$FN") $obj.Put("sn", "$SN") $obj.SetInfo $oRS.MoveNext Loop Any help much appreciated. Thanks Glyn |
||||||||
|
|
|||||||
' = chr(39) Maybe that helps? Or try to wrap your single quotes in double quotes |
||||||||
|
|
|||||||
I think you were talking about this? I don't know if this will work: Code: $oCmd.CommandText = "SELECT " $oCmd.CommandText = $oCmd.CommandText + $selectedProperties $oCmd.CommandText = $oCmd.CommandText + " FROM 'LDAP://Student.carshalton.ac.uk'" $oCmd.CommandText = $oCmd.CommandText + " WHERE objectCategory='user' " $oCmd.CommandText = $oCmd.CommandText + " AND description = " $oCmd.CommandText = $oCmd.CommandText + '"A'me Down"' $oCmd.CommandText = $oCmd.CommandText + " ORDER BY Name" |
||||||||
|
|
|||||||
Originally Posted By: Witto I think you were talking about this? I don't know if this will work: Code: $oCmd.CommandText = "SELECT " $oCmd.CommandText = $oCmd.CommandText + $selectedProperties $oCmd.CommandText = $oCmd.CommandText + " FROM 'LDAP://Student.carshalton.ac.uk'" $oCmd.CommandText = $oCmd.CommandText + " WHERE objectCategory='user' " $oCmd.CommandText = $oCmd.CommandText + " AND description = " $oCmd.CommandText = $oCmd.CommandText + '"A'me Down"' $oCmd.CommandText = $oCmd.CommandText + " ORDER BY Name" Hi Witto tried that but it did not work. I am sure its to do with the apostrophe in the SQL query. I did find this vbscript which when using apostrophe in SQL it does not like it. so someone created a vbscript to fix this. lsLastName = Replace(lsLastName, "'", "''") can this be converted into kix? Thanks Glyn |
||||||||
|
|
|||||||
I think your have to escape the single quote with another... try this. Code: $oCmd.CommandText = $oCmd.CommandText + "A''me Down" or $oCmd.CommandText = $oCmd.CommandText + "A'" + "'me Down" |
||||||||
|
|
|||||||
Nope still no go any other ideas |
||||||||
|
|
|||||||
Code: $oCmd.CommandText = $oCmd.CommandText + '"A ' + "'" + 'me Down "' |
||||||||
|
|
|||||||
Thanks witto for helping out & Allen, but that did not work either, its bugging the hell out of mw all other names without like john doe work fine!!! |
||||||||
|
|
|||||||
Code: $oCmd.CommandText = $oCmd.CommandText + "A"+Chr(39)+"me Down" |
||||||||
|
|
|||||||
Carshalton, eh? I did a course or two at the college. LDAP generally uses the Unix "\" convention for escaping characters (you'll see this often with "," in names), so try this: Code: $oCmd.CommandText = $oCmd.CommandText + '"A ' + "\'" + 'me Down "' |