Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Active Directory
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



modify AD computer script to run from locally authenticated accounton server

Active Directory


Reply
 
Thread Tools Search this Thread
  #1  
Old 10-12-2009
worldzfree
 
Posts: n/a
modify AD computer script to run from locally authenticated accounton server

Hello,

I have a script that I want to modify but am lost in applying the
correct syntax to move a computer object in Active Directory. Based
on what I have found in my searches I will need to bind directly to a
DC with alternate credentials. I have tried multiple iterations but
can't get it to work. Below is the original un-altered script that I
am trying improve upon.

------begin paste-----------
'get computer name
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2")
Set colItems = objWMIService.ExecQuery("Select Name from
Win32_ComputerSystem",,48)
For Each objItem in colItems
strPCName = objItem.Name
Next

'move computer object
Set objNewOU = GetObject("LDAP://OU=New
Container,DC=sub,DC=root,DC=local")
Set objMoveComputer = objNewOU.MoveHere _
("LDAP://CN=" & strPCName & ",CN=Computers,DC=sub,DC=root,DC=local",
"CN=" & strPCName)


--------end paste-----------
Reply With Quote
  #2  
Old 10-12-2009
Richard Mueller [MVP]
 
Posts: n/a
Re: modify AD computer script to run from locally authenticated account on server


"worldzfree" <arosette@gmail.com> wrote in message
news:35b466e3-7bec-46ef-8f77-3d82cd551f79@u1g2000pre.googlegroups.com...
> Hello,
>
> I have a script that I want to modify but am lost in applying the
> correct syntax to move a computer object in Active Directory. Based
> on what I have found in my searches I will need to bind directly to a
> DC with alternate credentials. I have tried multiple iterations but
> can't get it to work. Below is the original un-altered script that I
> am trying improve upon.
>
> ------begin paste-----------
> 'get computer name
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
> \cimv2")
> Set colItems = objWMIService.ExecQuery("Select Name from
> Win32_ComputerSystem",,48)
> For Each objItem in colItems
> strPCName = objItem.Name
> Next
>
> 'move computer object
> Set objNewOU = GetObject("LDAP://OU=New
> Container,DC=sub,DC=root,DC=local")
> Set objMoveComputer = objNewOU.MoveHere _
> ("LDAP://CN=" & strPCName & ",CN=Computers,DC=sub,DC=root,DC=local",
> "CN=" & strPCName)
>
>
> --------end paste-----------


First, you can retrieve the local computer name (the NetBIOS name) from the
wshNetwork object.

' Retrieve local computer name.
Set objNetwork = CreateObject("Wscript.Network")
strPCName = objNetwork.ComputerName

Next, use the OpenDSObject method of the LDAP namespace to bind to an object
with alternate credentials. Also, when moving an object, instead of
specifying the Common Name in the MoveHere method, use vbNullString.
Finally, the NetBIOS name of the computer, whether retrieved using WMI or
wshNetwork, may not match the common name of the computer object (the value
of the cn attribute). Instead, use the ADSystemInfo object to retrieve the
Distinguished Name of the computer. For example:
==========
Const ADS_SECURE_AUTHENTICATION = &H1

' Specify username to connect.
strUser = "MyDomain\JSMith"

' Specify password.
strPassword = "xzy321w

' Specify DN of new OU container.
strOU = "ou=New Container,dc=sub,dc=root,dc=local"

' Retrieve DN of local computer.
Set objSysInfo = CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.ComputerName

' Bind to new OU object in AD with alternate credentials.
Set objNS = GetObject("LDAP:")
Set objNewOU = objNS.OpenDSObject("LDAP://" & strOU, strUser, strPassword,
ADS_SECURE_AUTHENTICATION)

' Move the computer object in AD.
objNewOU.MoveHere "LDAP://" & strComputerDN, vbNullString

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


Reply With Quote
  #3  
Old 11-12-2009
worldzfree
 
Posts: n/a
Re: modify AD computer script to run from locally authenticatedaccount on server

On Dec 9, 7:34*pm, "Richard Mueller [MVP]" <rlmueller-
nos...@ameritech.nospam.net> wrote:
> "worldzfree" <arose...@gmail.com> wrote in message
>
> news:35b466e3-7bec-46ef-8f77-3d82cd551f79@u1g2000pre.googlegroups.com...
>
>
>
> > Hello,

>
> > I have a script that I want to modify but am lost in applying the
> > correct syntax to move a computer object in Active Directory. *Based
> > on what I have found in my searches I will need to bind directly to a
> > DC with alternate credentials. *I have tried multiple iterations but
> > can't get it to work. *Below is the original un-altered script that I
> > am trying improve upon.

>
> > ------begin paste-----------
> > 'get computer name
> > strComputer = "."
> > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
> > \cimv2")
> > Set colItems = objWMIService.ExecQuery("Select Name from
> > Win32_ComputerSystem",,48)
> > For Each objItem in colItems
> > strPCName = objItem.Name
> > Next

>
> > 'move computer object
> > Set objNewOU = GetObject("LDAP://OU=New
> > Container,DC=sub,DC=root,DC=local")
> > Set objMoveComputer = objNewOU.MoveHere _
> > ("LDAP://CN=" & strPCName & ",CN=Computers,DC=sub,DC=root,DC=local",
> > "CN=" & strPCName)

>
> > --------end paste-----------

>
> First, you can retrieve the local computer name (the NetBIOS name) from the
> wshNetwork object.
>
> ' Retrieve local computer name.
> Set objNetwork = CreateObject("Wscript.Network")
> strPCName = objNetwork.ComputerName
>
> Next, use the OpenDSObject method of the LDAP namespace to bind to an object
> with alternate credentials. Also, when moving an object, instead of
> specifying the Common Name in the MoveHere method, use vbNullString.
> Finally, the NetBIOS name of the computer, whether retrieved using WMI or
> wshNetwork, may not match the common name of the computer object (the value
> of the cn attribute). Instead, use the ADSystemInfo object to retrieve the
> Distinguished Name of the computer. For example:
> ==========
> Const ADS_SECURE_AUTHENTICATION = &H1
>
> ' Specify username to connect.
> strUser = "MyDomain\JSMith"
>
> ' Specify password.
> strPassword = "xzy321w
>
> ' Specify DN of new OU container.
> strOU = "ou=New Container,dc=sub,dc=root,dc=local"
>
> ' Retrieve DN of local computer.
> Set objSysInfo = CreateObject("ADSystemInfo")
> strComputerDN = objSysInfo.ComputerName
>
> ' Bind to new OU object in AD with alternate credentials.
> Set objNS = GetObject("LDAP:")
> Set objNewOU = objNS.OpenDSObject("LDAP://" & strOU, strUser, strPassword,
> ADS_SECURE_AUTHENTICATION)
>
> ' Move the computer object in AD.
> objNewOU.MoveHere "LDAP://" & strComputerDN, vbNullString
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab -http://www.rlmueller.net
> --


Thanks Richard! I have tried that code but I receive the following
error.

Line: 14
Char: 1
Error: Logon failure: account currently disabled
Code: 80070533
Source: Null

I have double-verified that the account credentials are entered
properly and the AD account is not disabled. Any ideas?
Reply With Quote
  #4  
Old 11-12-2009
worldzfree
 
Posts: n/a
Re: modify AD computer script to run from locally authenticatedaccount on server

On Dec 10, 10:34*am, worldzfree <worldzf...@gmail.com> wrote:
> On Dec 9, 7:34*pm, "Richard Mueller [MVP]" <rlmueller-
>
>
>
> nos...@ameritech.nospam.net> wrote:
> > "worldzfree" <arose...@gmail.com> wrote in message

>
> >news:35b466e3-7bec-46ef-8f77-3d82cd551f79@u1g2000pre.googlegroups.com...

>
> > > Hello,

>
> > > I have a script that I want to modify but am lost in applying the
> > > correct syntax to move a computer object in Active Directory. *Based
> > > on what I have found in my searches I will need to bind directly to a
> > > DC with alternate credentials. *I have tried multiple iterations but
> > > can't get it to work. *Below is the original un-altered script thatI
> > > am trying improve upon.

>
> > > ------begin paste-----------
> > > 'get computer name
> > > strComputer = "."
> > > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
> > > \cimv2")
> > > Set colItems = objWMIService.ExecQuery("Select Name from
> > > Win32_ComputerSystem",,48)
> > > For Each objItem in colItems
> > > strPCName = objItem.Name
> > > Next

>
> > > 'move computer object
> > > Set objNewOU = GetObject("LDAP://OU=New
> > > Container,DC=sub,DC=root,DC=local")
> > > Set objMoveComputer = objNewOU.MoveHere _
> > > ("LDAP://CN=" & strPCName & ",CN=Computers,DC=sub,DC=root,DC=local",
> > > "CN=" & strPCName)

>
> > > --------end paste-----------

>
> > First, you can retrieve the local computer name (the NetBIOS name) fromthe
> > wshNetwork object.

>
> > ' Retrieve local computer name.
> > Set objNetwork = CreateObject("Wscript.Network")
> > strPCName = objNetwork.ComputerName

>
> > Next, use the OpenDSObject method of the LDAP namespace to bind to an object
> > with alternate credentials. Also, when moving an object, instead of
> > specifying the Common Name in the MoveHere method, use vbNullString.
> > Finally, the NetBIOS name of the computer, whether retrieved using WMI or
> > wshNetwork, may not match the common name of the computer object (the value
> > of the cn attribute). Instead, use the ADSystemInfo object to retrieve the
> > Distinguished Name of the computer. For example:
> > ==========
> > Const ADS_SECURE_AUTHENTICATION = &H1

>
> > ' Specify username to connect.
> > strUser = "MyDomain\JSMith"

>
> > ' Specify password.
> > strPassword = "xzy321w

>
> > ' Specify DN of new OU container.
> > strOU = "ou=New Container,dc=sub,dc=root,dc=local"

>
> > ' Retrieve DN of local computer.
> > Set objSysInfo = CreateObject("ADSystemInfo")
> > strComputerDN = objSysInfo.ComputerName

>
> > ' Bind to new OU object in AD with alternate credentials.
> > Set objNS = GetObject("LDAP:")
> > Set objNewOU = objNS.OpenDSObject("LDAP://" & strOU, strUser, strPassword,
> > ADS_SECURE_AUTHENTICATION)

>
> > ' Move the computer object in AD.
> > objNewOU.MoveHere "LDAP://" & strComputerDN, vbNullString

>
> > --
> > Richard Mueller
> > MVP Directory Services
> > Hilltop Lab -http://www.rlmueller.net
> > --

>
> Thanks Richard! *I have tried that code but I receive the following
> error.
>
> Line: *14
> Char: *1
> Error: *Logon failure: *account currently disabled
> Code: *80070533
> Source: *Null
>
> I have double-verified that the account credentials are entered
> properly and the AD account is not disabled. *Any ideas?


Ok, I found references here (http://www.robvanderwoude.com/
vbstech_network_names_computer.php) on how to retrieve a name. I
changed:

Set objSysInfo = CreateObject("ADSystemInfo")

to

Set objSysInfo = CreateObject("WinNTSystemInfo")

and my script got farther along but then I have the same old error
that I was getting before which makes me think I need to do a DC
server bind earlier in the script. Thoughts?


Line: 18
Char: 1
Error: The specified domain either does not exist or could not be
contacted
Code: 8007054B
Source: (null)
Reply With Quote
  #5  
Old 11-12-2009
Richard Mueller [MVP]
 
Posts: n/a
Re: modify AD computer script to run from locally authenticated account on server


"worldzfree" <worldzfree@gmail.com> wrote in message
news:9dcceb0e-9ab9-4cb8-ae99-ef0258fbf7ec@13g2000prl.googlegroups.com...
On Dec 10, 10:34 am, worldzfree <worldzf...@gmail.com> wrote:
> On Dec 9, 7:34 pm, "Richard Mueller [MVP]" <rlmueller-
>
>
>
> nos...@ameritech.nospam.net> wrote:
> > "worldzfree" <arose...@gmail.com> wrote in message

>
> >news:35b466e3-7bec-46ef-8f77-3d82cd551f79@u1g2000pre.googlegroups.com...

>
> > > Hello,

>
> > > I have a script that I want to modify but am lost in applying the
> > > correct syntax to move a computer object in Active Directory. Based
> > > on what I have found in my searches I will need to bind directly to a
> > > DC with alternate credentials. I have tried multiple iterations but
> > > can't get it to work. Below is the original un-altered script that I
> > > am trying improve upon.

>
> > > ------begin paste-----------
> > > 'get computer name
> > > strComputer = "."
> > > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
> > > \cimv2")
> > > Set colItems = objWMIService.ExecQuery("Select Name from
> > > Win32_ComputerSystem",,48)
> > > For Each objItem in colItems
> > > strPCName = objItem.Name
> > > Next

>
> > > 'move computer object
> > > Set objNewOU = GetObject("LDAP://OU=New
> > > Container,DC=sub,DC=root,DC=local")
> > > Set objMoveComputer = objNewOU.MoveHere _
> > > ("LDAP://CN=" & strPCName & ",CN=Computers,DC=sub,DC=root,DC=local",
> > > "CN=" & strPCName)

>
> > > --------end paste-----------

>
> > First, you can retrieve the local computer name (the NetBIOS name) from
> > the
> > wshNetwork object.

>
> > ' Retrieve local computer name.
> > Set objNetwork = CreateObject("Wscript.Network")
> > strPCName = objNetwork.ComputerName

>
> > Next, use the OpenDSObject method of the LDAP namespace to bind to an
> > object
> > with alternate credentials. Also, when moving an object, instead of
> > specifying the Common Name in the MoveHere method, use vbNullString.
> > Finally, the NetBIOS name of the computer, whether retrieved using WMI
> > or
> > wshNetwork, may not match the common name of the computer object (the
> > value
> > of the cn attribute). Instead, use the ADSystemInfo object to retrieve
> > the
> > Distinguished Name of the computer. For example:
> > ==========
> > Const ADS_SECURE_AUTHENTICATION = &H1

>
> > ' Specify username to connect.
> > strUser = "MyDomain\JSMith"

>
> > ' Specify password.
> > strPassword = "xzy321w

>
> > ' Specify DN of new OU container.
> > strOU = "ou=New Container,dc=sub,dc=root,dc=local"

>
> > ' Retrieve DN of local computer.
> > Set objSysInfo = CreateObject("ADSystemInfo")
> > strComputerDN = objSysInfo.ComputerName

>
> > ' Bind to new OU object in AD with alternate credentials.
> > Set objNS = GetObject("LDAP:")
> > Set objNewOU = objNS.OpenDSObject("LDAP://" & strOU, strUser,
> > strPassword,
> > ADS_SECURE_AUTHENTICATION)

>
> > ' Move the computer object in AD.
> > objNewOU.MoveHere "LDAP://" & strComputerDN, vbNullString

>
> > --
> > Richard Mueller
> > MVP Directory Services
> > Hilltop Lab -http://www.rlmueller.net
> > --

>
> Thanks Richard! I have tried that code but I receive the following
> error.
>
> Line: 14
> Char: 1
> Error: Logon failure: account currently disabled
> Code: 80070533
> Source: Null
>
> I have double-verified that the account credentials are entered
> properly and the AD account is not disabled. Any ideas?


Ok, I found references here (http://www.robvanderwoude.com/
vbstech_network_names_computer.php) on how to retrieve a name. I
changed:

Set objSysInfo = CreateObject("ADSystemInfo")

to

Set objSysInfo = CreateObject("WinNTSystemInfo")

and my script got farther along but then I have the same old error
that I was getting before which makes me think I need to do a DC
server bind earlier in the script. Thoughts?


Line: 18
Char: 1
Error: The specified domain either does not exist or could not be
contacted
Code: 8007054B
Source: (null)

The WinNTSystemInfo object returns the NT name (pre-Windows 2000 logon name)
of the user, not the Distinguished Name (DN). This makes sense, but does not
help you, you need the DN. I've heard that a server bind is sometimes
necessary, the only drawback is that you need to specify a server. The
following might help:

' Add the following.
Const ADS_SERVER_BIND = &H200

' Then use:
strServer = "MyServer"
Set objNewOU = objNS.OpenDSObject("LDAP://" & strServer & "/" & strOU,
strUser, strPassword, _
ADS_SECURE_AUTHENTICATION Or ADS_SERVER_BIND)

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


Reply With Quote
  #6  
Old 11-12-2009
worldzfree
 
Posts: n/a
Re: modify AD computer script to run from locally authenticatedaccount on server

>
> The WinNTSystemInfo object returns the NT name (pre-Windows 2000 logon name)
> of the user, not the Distinguished Name (DN). This makes sense, but does not
> help you, you need the DN. I've heard that a server bind is sometimes
> necessary, the only drawback is that you need to specify a server. The
> following might help:
>
> ' Add the following.
> Const ADS_SERVER_BIND = &H200
>
> ' Then use:
> strServer = "MyServer"
> Set objNewOU = objNS.OpenDSObject("LDAP://" & strServer & "/" & strOU,
> strUser, strPassword, _
> * * ADS_SECURE_AUTHENTICATION Or ADS_SERVER_BIND)
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab -http://www.rlmueller.net
> --


Richard,

I am still stuck. I switched back to the "ADSystemInfo" but I assume
I will need to pass credentials to run ADSystemInfo from AD? Here is
the code as it stands.


------begin paste ---------

Const ADS_SERVER_BIND = &H200
Const ADS_SECURE_AUTHENTICATION = &H1

' DC to bind to
strServer = "domaincontroller"

' Specify username to connect.
strUser = "domain\account"

' Specify password.
strPassword = "password"

' Specify DN of new OU container.
strOU = "OU=New Container,DC=sub,DC=root,DC=local"

' Retrieve DN of local computer.
Set objSysInfo = CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.ComputerName

' Bind to new OU object in AD with alternate credentials.
Set objNS = GetObject("LDAP:")
Set objNewOU = objNS.OpenDSObject("LDAP://" & strServer & "/" & strOU,
strUser, strPassword, _
ADS_SECURE_AUTHENTICATION Or ADS_SERVER_BIND)

' Move the computer object in AD.
objNewOU.MoveHere "LDAP://" & strComputerDN, vbNullString

--------end paste----------


The error I get is:

Line: 18
Char: 1
Error: Logon failure: account currently disabled
Code: 80070533
Source: Null


Frustrating.

Reply With Quote
  #7  
Old 11-12-2009
Richard Mueller [MVP]
 
Posts: n/a
Re: modify AD computer script to run from locally authenticated account on server


"worldzfree" <worldzfree@gmail.com> wrote in message
news:470d8eee-0dbf-429f-9d1f-94c4b5ce26fe@x25g2000prf.googlegroups.com...
>
> The WinNTSystemInfo object returns the NT name (pre-Windows 2000 logon
> name)
> of the user, not the Distinguished Name (DN). This makes sense, but does
> not
> help you, you need the DN. I've heard that a server bind is sometimes
> necessary, the only drawback is that you need to specify a server. The
> following might help:
>
> ' Add the following.
> Const ADS_SERVER_BIND = &H200
>
> ' Then use:
> strServer = "MyServer"
> Set objNewOU = objNS.OpenDSObject("LDAP://" & strServer & "/" & strOU,
> strUser, strPassword, _
> ADS_SECURE_AUTHENTICATION Or ADS_SERVER_BIND)
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab -http://www.rlmueller.net
> --


Richard,

I am still stuck. I switched back to the "ADSystemInfo" but I assume
I will need to pass credentials to run ADSystemInfo from AD? Here is
the code as it stands.


------begin paste ---------

Const ADS_SERVER_BIND = &H200
Const ADS_SECURE_AUTHENTICATION = &H1

' DC to bind to
strServer = "domaincontroller"

' Specify username to connect.
strUser = "domain\account"

' Specify password.
strPassword = "password"

' Specify DN of new OU container.
strOU = "OU=New Container,DC=sub,DC=root,DC=local"

' Retrieve DN of local computer.
Set objSysInfo = CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.ComputerName

' Bind to new OU object in AD with alternate credentials.
Set objNS = GetObject("LDAP:")
Set objNewOU = objNS.OpenDSObject("LDAP://" & strServer & "/" & strOU,
strUser, strPassword, _
ADS_SECURE_AUTHENTICATION Or ADS_SERVER_BIND)

' Move the computer object in AD.
objNewOU.MoveHere "LDAP://" & strComputerDN, vbNullString

--------end paste----------


The error I get is:

Line: 18
Char: 1
Error: Logon failure: account currently disabled
Code: 80070533
Source: Null


Frustrating.
===========
Yes, that makes sense. You cannot use ADSystemInfo if you are not
authenticated to the domain.

I would try again, but reversing the steps, so you bind to the OU object
with alternate credentials first, then use ADSystemInfo to retrieve the DN
of the local computer. Hopefully, once you are authenticated, you can do
this.

Otherwise, it becomes difficult to retrieve the DN of the local computer.
The only other reliable solution is to use the NameTranslate object to
convert the NetBIOS name of the computer retrieved from the wshNetwork
object into the DN. You can use alternate credentials with NameTranslate.
This is getting complicated, but that's what happens when you aren't
authenticated. The final solution, if the suggestion above does not work,
would be:
========
Const ADS_SECURE_AUTHENTICATION = &H1
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

' Specify NetBIOS name of domain.
strDomain = "MyDomain"

' Specify username to connect.
strUser = "JSMith"

' Specify password.
strPassword = "xzy321w

' Retrieve NetBIOS name of local computer.
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

' Use NameTranslate to convert NT form of computer name into DN.
Set objTrans = CreateObject("NameTranslate")
' Initialize by locating Global Catalog. Specify credentials.
objTrans.InitEx ADS_NAME_INITTYPE_GC, "", strUser, strDomain, strPassword
' Use the Set method to specify the NT format of the name.
objTrans.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strComputer
' Use the Get method to retrieve the DN.
strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)

' Specify DN of new OU container.
strOU = "ou=New Container,dc=sub,dc=root,dc=local"

' Bind to new OU object in AD with alternate credentials.
Set objNS = GetObject("LDAP:")
Set objNewOU = objNS.OpenDSObject("LDAP://" & strOU, _
strDomain & "\" & strUser, strPassword, ADS_SECURE_AUTHENTICATION)

' Move the computer object in AD.
objNewOU.MoveHere "LDAP://" & strComputerDN, vbNullString
========
I haven't tested the above, but I've done similar work with alternate
credentials. Notice I've changed the meaning of strUser and added strDomain,
to accomodate the NameTranslate object.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


Reply With Quote
  #8  
Old 12-12-2009
worldzfree
 
Posts: n/a
Re: modify AD computer script to run from locally authenticatedaccount on server

Thanks Richard. I got something hobbled together to get it to work.
I had to add a "$" at the end of the computer name translation and
then add the server bind code further down. There may be a cleaner
approach but this works for me. Again, thanks.

-------begin paste---------

' Constants for the NameTranslate object and server-bind
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Const ADS_SERVER_BIND = &H200
Const ADS_SECURE_AUTHENTICATION = &H1

' DC to bind to
strServer = "domaincontroller"

' Specify NetBIOS name of domain.
strDomain = "domain"

' Specify username to connect.
strUser = "moveaccount"

' Specify password.
strPassword = "123456"

' Retrieve NetBIOS name of local computer.
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

' Use NameTranslate to convert NT form of computer name into DN.
Set objTrans = CreateObject("NameTranslate")
' Initialize by locating Global Catalog. Specify credentials.
objTrans.InitEx ADS_NAME_INITTYPE_GC, "", strUser, strDomain,
strPassword
' Use the Set method to specify the NT format of the name.
objTrans.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strComputer & "$"
' Use the Get method to retrieve the DN.
strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)

' Specify DN of new OU container.
strOU = "OU=New Container,DC=sub,DC=root,DC=local"

' Bind to new OU object in AD with alternate credentials.
Set objNS = GetObject("LDAP:")
Set objNewOU = objNS.OpenDSObject("LDAP://" & strServer & "/" & strOU,
strUser, strPassword, _
ADS_SECURE_AUTHENTICATION Or ADS_SERVER_BIND)

' Move the computer object in AD.
objNewOU.MoveHere "LDAP://" & strComputerDN, vbNullString

---------end paste--------------
Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Active Directory


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "modify AD computer script to run from locally authenticated accounton server"
Thread Thread Starter Forum Replies Last Post
Need help to modify ip address of Wins Server AerospaceGuy Networking & Security 1 22-08-2011 04:55 PM
Can't login locally to the server John Small Business Server 9 24-07-2009 06:22 AM
How to read and modify excel file using PHP script JamesB Software Development 3 18-03-2009 12:59 AM
Server still functions, but cannot log in locally or remotely Chris Benton Windows Server Help 2 28-08-2008 02:36 AM
Modify Permission to Home Folder Script Masti Windows Server Help 1 23-04-2008 09:15 AM


All times are GMT +5.5. The time now is 09:09 PM.