Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: Rename Computer

HTVi
TV Discussion Newsgroups

Rename Computer
"Mike" <reply[ at ]togroup.com> 5/2/2007 2:16:08 PM
Hello, I'm running the script below to rename computers in a domain from a
comma separated list. I'm getting an error (8007200E) "The directory server
is busy" when it gets to objComputer.Put "sAMAccountName",newname&"$"

I've tried it at different times of the day when the server is not busy but
still getting the same error. I didn't write this script so I don't fully
understand what it is attempting but I'm hoping someone in here can shed
some light on it. All the variables (domain and credentials) are correct
with sufficient permissions.

Regards,
Mike.







Set objNetwork = CreateObject("WScript.Network")
strComputer = uCase(objNetwork.ComputerName)

strBase="<LDAP://dc=domain,dc=local>;"
strFilter="(cn="+strComputer+");"
strAttrs="cn,distinguishedName;"
strScope="Subtree"
strU = "ntconnect"
strP = "ntconnect"

Set objConn=CreateObject("ADODB.Connection")
objConn.Provider="ADsDSOObject"
objConn.Open "Active Directory Provider"
Set objRS=objConn.Execute(strBase&strFilter&strAttrs&strScope)
objRS.MoveFirst
adloc=objRS.Fields("distinguishedName")
poscomma=InStr(adloc,",")+1
adloc=Mid(adloc,poscomma,1000)


Set file_sys_obj = CreateObject("Scripting.FileSystemObject")
Set file_read = file_sys_obj.GetFile("\\server\netlogon\names.txt")
Set txtstream=file_read.openastextstream(1)
Do until txtstream.AtEndOfStream
regel=txtstream.readline
testname=ucase(mid(regel,1,InStr(regel,",")-1))
newname=UCase(Mid(regel,InStr(regel,",")+1,1000))
If strcomputer = testname Then
oldcn="cn="+strcomputer
newcn="cn="+newname
Set objCont=GetObject ("LDAP://"&adloc)
objCont.MoveHere "LDAP://" & oldcn & "," & adloc, newcn
strObject=newcn & "," & adloc
Set objComputer=GetObject("LDAP://"&strObject)
objComputer.Put "DNSHostName",newname&".domain.local"
objComputer.SetInfo
objComputer.Put "sAMAccountName",newname&"$"
objComputer.SetInfo
objComputer.Put "displayName",newname&"$"
objComputer.SetInfo


Set oShell=CreateObject("WScript.Shell")
oShell.RegWrite
"HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\ComputerName",newname,"REG_SZ"
oShell.RegWrite
"HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName",newname,"REG_SZ"
oShell.RegWrite
"HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname",newname,"REG_SZ"
oShell.RegWrite
"HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV
Hostname",newname,"REG_SZ"
End If
loop
txtstream.close

Re: Rename Computer
"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> 5/2/2007 5:49:35 PM
Not sure what the problem might be, but sAMAccountName's are limited to 20
characters (including the trailing "$") and should not have any of the
following characters:

" / \ [ ] : ; | , + * ? < >

Other than that, the value must be unique in the domain. Also, you only need
to invoke SetInfo once per object, after all values have been assigned.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"Mike" <reply[ at ]togroup.com> wrote in message
news:OaWUxRMjHHA.4768[ at ]TK2MSFTNGP05.phx.gbl...
[Quoted Text]
> Hello, I'm running the script below to rename computers in a domain from a
> comma separated list. I'm getting an error (8007200E) "The directory
> server is busy" when it gets to objComputer.Put
> "sAMAccountName",newname&"$"
>
> I've tried it at different times of the day when the server is not busy
> but still getting the same error. I didn't write this script so I don't
> fully understand what it is attempting but I'm hoping someone in here can
> shed some light on it. All the variables (domain and credentials) are
> correct with sufficient permissions.
>
> Regards,
> Mike.
>
>
>
>
>
>
>
> Set objNetwork = CreateObject("WScript.Network")
> strComputer = uCase(objNetwork.ComputerName)
>
> strBase="<LDAP://dc=domain,dc=local>;"
> strFilter="(cn="+strComputer+");"
> strAttrs="cn,distinguishedName;"
> strScope="Subtree"
> strU = "ntconnect"
> strP = "ntconnect"
>
> Set objConn=CreateObject("ADODB.Connection")
> objConn.Provider="ADsDSOObject"
> objConn.Open "Active Directory Provider"
> Set objRS=objConn.Execute(strBase&strFilter&strAttrs&strScope)
> objRS.MoveFirst
> adloc=objRS.Fields("distinguishedName")
> poscomma=InStr(adloc,",")+1
> adloc=Mid(adloc,poscomma,1000)
>
>
> Set file_sys_obj = CreateObject("Scripting.FileSystemObject")
> Set file_read = file_sys_obj.GetFile("\\server\netlogon\names.txt")
> Set txtstream=file_read.openastextstream(1)
> Do until txtstream.AtEndOfStream
> regel=txtstream.readline
> testname=ucase(mid(regel,1,InStr(regel,",")-1))
> newname=UCase(Mid(regel,InStr(regel,",")+1,1000))
> If strcomputer = testname Then
> oldcn="cn="+strcomputer
> newcn="cn="+newname
> Set objCont=GetObject ("LDAP://"&adloc)
> objCont.MoveHere "LDAP://" & oldcn & "," & adloc, newcn
> strObject=newcn & "," & adloc
> Set objComputer=GetObject("LDAP://"&strObject)
> objComputer.Put "DNSHostName",newname&".domain.local"
> objComputer.SetInfo
> objComputer.Put "sAMAccountName",newname&"$"
> objComputer.SetInfo
> objComputer.Put "displayName",newname&"$"
> objComputer.SetInfo
>
>
> Set oShell=CreateObject("WScript.Shell")
> oShell.RegWrite
> "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\ComputerName",newname,"REG_SZ"
> oShell.RegWrite
> "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName",newname,"REG_SZ"
> oShell.RegWrite
> "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname",newname,"REG_SZ"
> oShell.RegWrite
> "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV
> Hostname",newname,"REG_SZ"
> End If
> loop
> txtstream.close


Re: Rename Computer
"Mike" <reply[ at ]togroup.com> 5/3/2007 2:51:26 AM

Hi Richard,

Thanks for your reply. Of course I am using a unique names, maximum of 15
characters and do not include any banned characters. Thanks for your advice
on the Set.Info, I switched the script around as per below; now it fails on
the Set.Info line, same error code 8007200E, error the directory service is
busy. source: (null).

objComputer.Put "DNSHostName",newname&".domain.local"
objComputer.Put "sAMAccountName",newname&"$"
objComputer.Put "displayName",newname&"$"
objComputer.SetInfo

Regards,
Mike.



"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> wrote in
message news:OCC$XJOjHHA.5012[ at ]TK2MSFTNGP04.phx.gbl...
[Quoted Text]
> Not sure what the problem might be, but sAMAccountName's are limited to 20
> characters (including the trailing "$") and should not have any of the
> following characters:
>
> " / \ [ ] : ; | , + * ? < >
>
> Other than that, the value must be unique in the domain. Also, you only
> need to invoke SetInfo once per object, after all values have been
> assigned.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "Mike" <reply[ at ]togroup.com> wrote in message
> news:OaWUxRMjHHA.4768[ at ]TK2MSFTNGP05.phx.gbl...
>> Hello, I'm running the script below to rename computers in a domain from
>> a comma separated list. I'm getting an error (8007200E) "The directory
>> server is busy" when it gets to objComputer.Put
>> "sAMAccountName",newname&"$"
>>
>> I've tried it at different times of the day when the server is not busy
>> but still getting the same error. I didn't write this script so I don't
>> fully understand what it is attempting but I'm hoping someone in here can
>> shed some light on it. All the variables (domain and credentials) are
>> correct with sufficient permissions.
>>
>> Regards,
>> Mike.
>>
>>
>>
>>
>>
>>
>>
>> Set objNetwork = CreateObject("WScript.Network")
>> strComputer = uCase(objNetwork.ComputerName)
>>
>> strBase="<LDAP://dc=domain,dc=local>;"
>> strFilter="(cn="+strComputer+");"
>> strAttrs="cn,distinguishedName;"
>> strScope="Subtree"
>> strU = "ntconnect"
>> strP = "ntconnect"
>>
>> Set objConn=CreateObject("ADODB.Connection")
>> objConn.Provider="ADsDSOObject"
>> objConn.Open "Active Directory Provider"
>> Set objRS=objConn.Execute(strBase&strFilter&strAttrs&strScope)
>> objRS.MoveFirst
>> adloc=objRS.Fields("distinguishedName")
>> poscomma=InStr(adloc,",")+1
>> adloc=Mid(adloc,poscomma,1000)
>>
>>
>> Set file_sys_obj = CreateObject("Scripting.FileSystemObject")
>> Set file_read = file_sys_obj.GetFile("\\server\netlogon\names.txt")
>> Set txtstream=file_read.openastextstream(1)
>> Do until txtstream.AtEndOfStream
>> regel=txtstream.readline
>> testname=ucase(mid(regel,1,InStr(regel,",")-1))
>> newname=UCase(Mid(regel,InStr(regel,",")+1,1000))
>> If strcomputer = testname Then
>> oldcn="cn="+strcomputer
>> newcn="cn="+newname
>> Set objCont=GetObject ("LDAP://"&adloc)
>> objCont.MoveHere "LDAP://" & oldcn & "," & adloc, newcn
>> strObject=newcn & "," & adloc
>> Set objComputer=GetObject("LDAP://"&strObject)
>> objComputer.Put "DNSHostName",newname&".domain.local"
>> objComputer.SetInfo
>> objComputer.Put "sAMAccountName",newname&"$"
>> objComputer.SetInfo
>> objComputer.Put "displayName",newname&"$"
>> objComputer.SetInfo
>>
>>
>> Set oShell=CreateObject("WScript.Shell")
>> oShell.RegWrite
>> "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\ComputerName",newname,"REG_SZ"
>> oShell.RegWrite
>> "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName",newname,"REG_SZ"
>> oShell.RegWrite
>> "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname",newname,"REG_SZ"
>> oShell.RegWrite
>> "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV
>> Hostname",newname,"REG_SZ"
>> End If
>> loop
>> txtstream.close
>
>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen