Hi
I'm having a problem when running the following script from local admin account. It works perfect when I run it from domain member account.
==================================================================
Option Explicit
Dim strNTName, strFileLog, strComputerName
Dim strDomain, strComputerDN
Dim objTrans, objComputer, objGroup, objLogFile, objFSO, objFile, objNetwork
' Constants for NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Set objNetwork = CreateObject("Wscript.Network")
strComputerName = ucase((objnetwork.computername))
' Specify the files.
strFileLog = "C:\AddComp_log.txt"
' Specify the NetBIOS name of the domain.
strDomain = "XYZ"
' Bind to the group object.
Set objGroup = GetObject("LDAP://CN=Group_Test,OU=Groups,OU=Resources,OU=IT,OU=City,DC=abc,DC=test,DC=com,DC=us")
' Use NameTranslate to convert NetBIOS names to Distinguished Names.
Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.
objTrans.Init ADS_NAME_INITTYPE_GC, ""
' Open the file to write Log messages
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.CreateTextFile(strFileLog,True)
' Append "$" to end of NetBIOS name for computers.
strNTName = strComputerName & "$"
objLogFile.WriteLine "Network Computer Name: " & strComputerName
objLogFile.WriteLine "NetBIOS Name: " & strNTName
' Convert NT names to Distinguished Names.
' Use the Set method to specify the NT format of the user name.
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strNTName
If Err.Number<>0 Then
objLogFile.WriteLine "Error finding computer: " & strNTName
Err.Clear
Else
' Use the Get method to retrieve the Distinguished Name.
strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)
objLogFile.WriteLine "Distinguished Name: " & strComputerDN
' Bind to computer object.
Set objComputer = GetObject("LDAP://" & strComputerDN)
' Check if computer is already a member of the group.
If (objGroup.IsMember(objComputer.AdsPath) = False) Then
' Add the computer to the group.
objGroup.Add(objComputer.AdsPath)
objLogFile.WriteLine "Computer Successfully added: " & strComputerName
Else
objLogFile.WriteLine " Computer is already member: " & strComputerName
End If
End If
On Error GoTo 0
' Close the file
objLogFile.Close
==================================================================
When I executed the script from local admin account
There's an error:
The specified domain either does not exist or could not be contacted.
I'f I logon as domain member account the script works perfect.
I know it's something to do with the permission to add a computer object to the "Group_Test" on AD.
Is there anyway to set the permission using domain account in the script above? So when I execute the script from local admin account it would add the computer object to the "Group_Test" in the Active Directory.
PS: I don't want the local admin user to be part of domain account.
Your help really much appreciated
I'm having a problem when running the following script from local admin account. It works perfect when I run it from domain member account.
==================================================================
Option Explicit
Dim strNTName, strFileLog, strComputerName
Dim strDomain, strComputerDN
Dim objTrans, objComputer, objGroup, objLogFile, objFSO, objFile, objNetwork
' Constants for NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Set objNetwork = CreateObject("Wscript.Network")
strComputerName = ucase((objnetwork.computername))
' Specify the files.
strFileLog = "C:\AddComp_log.txt"
' Specify the NetBIOS name of the domain.
strDomain = "XYZ"
' Bind to the group object.
Set objGroup = GetObject("LDAP://CN=Group_Test,OU=Groups,OU=Resources,OU=IT,OU=City,DC=abc,DC=test,DC=com,DC=us")
' Use NameTranslate to convert NetBIOS names to Distinguished Names.
Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.
objTrans.Init ADS_NAME_INITTYPE_GC, ""
' Open the file to write Log messages
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.CreateTextFile(strFileLog,True)
' Append "$" to end of NetBIOS name for computers.
strNTName = strComputerName & "$"
objLogFile.WriteLine "Network Computer Name: " & strComputerName
objLogFile.WriteLine "NetBIOS Name: " & strNTName
' Convert NT names to Distinguished Names.
' Use the Set method to specify the NT format of the user name.
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strNTName
If Err.Number<>0 Then
objLogFile.WriteLine "Error finding computer: " & strNTName
Err.Clear
Else
' Use the Get method to retrieve the Distinguished Name.
strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)
objLogFile.WriteLine "Distinguished Name: " & strComputerDN
' Bind to computer object.
Set objComputer = GetObject("LDAP://" & strComputerDN)
' Check if computer is already a member of the group.
If (objGroup.IsMember(objComputer.AdsPath) = False) Then
' Add the computer to the group.
objGroup.Add(objComputer.AdsPath)
objLogFile.WriteLine "Computer Successfully added: " & strComputerName
Else
objLogFile.WriteLine " Computer is already member: " & strComputerName
End If
End If
On Error GoTo 0
' Close the file
objLogFile.Close
==================================================================
When I executed the script from local admin account
There's an error:
The specified domain either does not exist or could not be contacted.
I'f I logon as domain member account the script works perfect.
I know it's something to do with the permission to add a computer object to the "Group_Test" on AD.
Is there anyway to set the permission using domain account in the script above? So when I execute the script from local admin account it would add the computer object to the "Group_Test" in the Active Directory.
PS: I don't want the local admin user to be part of domain account.
Your help really much appreciated