Jump to content

Active Directory object move


Recommended Posts

Hello,

I have search for help on the following problem. This might be a bug. I have converted the following VBScript to Autoit and I am receiving the following error.

The VBScript works fine but just can get it to work in AutoIT

MoveComputer.au3 (39) : ==> The requested action with this object has failed.:

$objOU.MoveHere ($strADsPath, "")

$objOU.MoveHere ($strADsPath, "")^ ERROR

The MsgBox command works and displays the current ADS Path. So I know it is connecting to AD and pulling information. When it hits the move command it falls. Any help would be greatly appreciated

Note. Both login ID and ID used in the script have Domain Admin rights

$wfID = "xxxxx" ; $CmdLine[1]
$wfPass = "xxxxx" ;$CmdLine[2]

Const $ADS_SCOPE_SUBTREE = 2

$objOU = ObjGet("LDAP://OU=Workstations,OU=Pasteur,OU=Corp,DC=wf,DC=local")

$objConnection = ObjCreate("ADODB.Connection")
$objCommand = ObjCreate("ADODB.Command")
$objConnection.Provider = "ADsDSOObject"

$objConnection.Properties ("User ID") = "wf\" & $wfID
$objConnection.Properties ("Password") = $wfPass
$objConnection.Properties ("Encrypt Password") = 1
$objConnection.Properties ("ADSI Flag") = 1

$objConnection.Open ("Active Directory Provider")
$objCommand.ActiveConnection = $objConnection

$objCommand.Properties ("Page Size") = 1000
$objCommand.Properties ("Searchscope") = $ADS_SCOPE_SUBTREE

;  $objCommand.CommandText = "SELECT ADsPath FROM 'LDAP://dc=WF,dc=local' WHERE objectCategory='computer' " & "AND Name='WF-6789'"
$objCommand.CommandText = "SELECT ADsPath, distinguishedName, Name FROM 'LDAP://dc=WF,dc=local' WHERE objectCategory='computer' AND Name='WF-6789'"
$objRecordSet = $objCommand.Execute

$objRecordSet.MoveFirst ()

While Not $objRecordSet.EOF ()
    $strADsPath = $objRecordSet.Fields ("ADsPath").Value
    MsgBox(4096, "", "Current path = " & $strADsPath)
    $objOU.MoveHere ($strADsPath, "")
    $objRecordSet.MoveNext ()
WEnd
Link to comment
Share on other sites

$objOU = ObjGet("LDAP://OU=Workstations,OU=Pasteur,OU=Corp,DC=wf,DC=local")

; ...

While Not $objRecordSet.EOF ()
    $strADsPath = $objRecordSet.Fields ("ADsPath").Value
    MsgBox(4096, "", "Current path = " & $strADsPath)
    $objOU.MoveHere ($strADsPath, "")
    $objRecordSet.MoveNext ()
WEndoÝ÷ Ûú®¢×ºÛayø«²Ûb쨺ëÓ~¨n3Êâ@1¶²hÄƲmè­v'gßÛNn1µÊ+­ç- Þnèç$jëh×6
$objOU = ObjGet("LDAP://OU=Workstations,OU=Pasteur,OU=Corp,DC=wf,DC=local")
If IsObj($objOU) Then
    MsgBox(64, "Debug", "$objOU is object.")
Else
    MsgBox(16, "Debug", "$objOU is not an object!")
EndIf

; ...

While Not $objRecordSet.EOF ()
    $strADsPath = $objRecordSet.Fields ("ADsPath").Value
    MsgBox(4096, "", "Current path = " & $strADsPath)
    $objOU.MoveHere ($strADsPath, "")
    $objRecordSet.MoveNext ()
WEnd

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I have not used ".MoveHere" before, however I would think this line should be different

$objOU.MoveHere ($strADsPath, "")

is either

$objOU.MoveHere ($strADsPath)

or.....

$objOU.MoveHere ($strADsPath, "C:\location\folder\")

... move from "here" to "here" idea

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

PsaltyDS

Thanks,

Object is reporting as correct

If IsObj($objOU) Then

MsgBox(64, "Debug", "$objOU is object.")

Else

MsgBox(16, "Debug", "$objOU is not an object!")

EndIf

Valuater

Thanks,

The format for .MoveHere ($strADsPath, "") is

object reference .MoveHere(parameter 1, parameter 2)

First parameter is the current location of the object

Second parameter is used for renaming the object during the move, But sine I am not renaming the object I pass a Null variable as the second parameter.

Edited by madmikep
Link to comment
Share on other sites

Valuater

Thanks,

The format for .MoveHere ($strADsPath, "") is

object reference .MoveHere(parameter 1, parameter 2)

First parameter is the current location of the object

Second parameter is used for renaming the object during the move, But sine I am not renaming the object I pass a Null variable as the second parameter.

Hmm... from this site: IADsContainer::MoveHere

In Visual Basic applications, you can pass vbNullString as the second parameter when moving an object from one container to another.

Set newobj = cont.MoveHere("LDAP://cn=jeffsmith,ou=sale,dc=dom,dc=com", vbNullString)

However, you cannot do the same with VBScript. This is because VBScript maps vbNullString to an empty string instead of to a null string, as does Visual Basic. You must use the RDN explicitly, as shown in the previous example.

That brings me to something I don't know... is there a difference in AutoIt between true null and "" (empty string)...

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Here is the VBscript that works correctly

CODE
objOU.MoveHere strADsPath, vbNullString

Convert it to Autoit should be

CODE
$objOU.MoveHere($strADsPath,"") I have evey tried

$objOU.MoveHere($strADsPath,"vbNullString") with the same error

I think this might be a bug in AutoIt, but not sure.

CODE
On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Set objOU = GetObject("LDAP://OU=Workstations,OU=Pasteur,OU=Corp,DC=wf,DC=local")

Set objConnection = CreateObject("ADODB.Connection")

Set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"

objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _

"SELECT ADsPath FROM 'LDAP://dc=WF,dc=local' WHERE objectCategory='computer' " & "AND Name='WF-6789'"

Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Do Until objRecordSet.EOF

strADsPath = objRecordSet.Fields("ADsPath").Value

objOU.MoveHere strADsPath, vbNullString

objRecordSet.MoveNext

Loop

Link to comment
Share on other sites

From the MS "ScriptingGuys" site:

By the way, you dont actually have to include the Null parameter; if theres no second parameter MoveHere will assume the second parameter is Null. We show it here just so you know that MoveHere accepts two parameters.

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to comment
Share on other sites

Did you consider:

$objOU.MoveHere ('"' & $strADsPath & '"', "")

That is putting singlequote doublequote singlequote around the value in $strADsPath... :)

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to comment
Share on other sites

Here is the VBscript that works correctly

objOU.MoveHere strADsPath, vbNullString

Convert it to Autoit should be

$objOU.MoveHere($strADsPath,"")

I have evey tried

$objOU.MoveHere($strADsPath,"vbNullString")

with the same error

I think this might be a bug in AutoIt, but not sure.

In some spheres, NUL is a special case. It's not 0 or "", it's nothing. But I don't know if that applies to AutoIt variables. Some things to try:

First, as jefhal has recommended, try quotes around the first value, and try leaving the second parameter off entirely.

To go off on my NUL tangent, you could try:

Dim $Nul ; no preset value at all
$objOU.MoveHere($strADsPath,$Nul)oÝ÷ ØêÚºÚ"µÍ[H    ÌÍÓ[HÚ
NÈ][[ÈÈÙ[]H[ÌÍÛØÕK[ÝRJ    ÌÍÜÝQÔ]    ÌÍÓ[
oÝ÷ ØêÞ½éÚºÚ"µÍ[H   ÌÍÓ[H[JÚ
JNÈ][[ÈÈÙ[]H[ÌÍÛØÕK[ÝRJ   ÌÍÜÝQÔ]    ÌÍÓ[

I've gone off the deep end and this may be a wild goose chase, sorry...

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

From the MS "ScriptingGuys" site:

By the way, you donât actually have to include the Null parameter; if thereâs no second parameter MoveHere will assume the second parameter is Null. We show it here just so you know that MoveHere accepts two parameters.

Thanks, jefhal

But,

This would not be the first time that the ScriptingGuys gave out incorrect information. I ran across a script that they published that did not work correctly they for got to include a Set command for a Getobject

IF you do not include the second parameter in the VBscript it will error out âunless you have an ON Error resume notâ with the following error âWindows Script Hostâ WSH. Error: Wrong number of arguments or invalid property assignment: objOU.MoveHere code 800A01c2

The second parameter is required

Edited by madmikep
Link to comment
Share on other sites

Did you consider:

$objOU.MoveHere ('"' & $strADsPath & '"', "")

That is putting singlequote doublequote singlequote around the value in $strADsPath... :)

Thanks again,

I did try this with the same result

$objOU.MoveHere ('"' & $strADsPath & '"', "")

Link to comment
Share on other sites

In some spheres, NUL is a special case. It's not 0 or "", it's nothing. But I don't know if that applies to AutoIt variables. Some things to try:

First, as jefhal has recommended, try quotes around the first value, and try leaving the second parameter off entirely.

To go off on my NUL tangent, you could try:

Dim $Nul ; no preset value at all
$objOU.MoveHere($strADsPath,$Nul)oÝ÷ ØêÚºÚ"µÍ[H    ÌÍÓ[HÚ
NÈ][[ÈÈÙ[]H[ÌÍÛØÕK[ÝRJ    ÌÍÜÝQÔ]    ÌÍÓ[
oÝ÷ ØêÞ½éÚºÚ"µÍ[H   ÌÍÓ[H[JÚ
JNÈ][[ÈÈÙ[]H[ÌÍÛØÕK[ÝRJ   ÌÍÜÝQÔ]    ÌÍÓ[

I've gone off the deep end and this may be a wild goose chase, sorry...

:)

PsaltyDS,

I also try the Dims no go and just for the hell of it I even tried Dim $Nul = Dec("00")

Edited by madmikep
Link to comment
Share on other sites

  • 6 months later...

I know this is an old thread, but I'm posting the following for reference purposes:

;Seems to work...
$computerName = @ComputerName ;Change as needed

$strNewParentDN = "LDAP://OU=Accounting,OU=Administrative,DC=example,DC=com"
$strObjectDN    = "LDAP://CN=" & $computerName & ",OU=machines,DC=example,DC=com"
$strObjectRDN   = "CN=" & $computerName

$objCont = ObjGet($strNewParentDN)
$objCont.MoveHere($strObjectDN, $strObjectRDN)
Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...