Question Hello, I have this script which modifies the site assignment for a subnet in Active Directory:
' This code updates the site assignment of a subnet object.
' ------ SCRIPT CONFIGURATION ------
strNewSiteName = "<SiteName>" ' e.g. "Raleigh"
strSubnetName = "<SubnetName>" ' e.g. "192.168.1.0/24"
' ------ END CONFIGURATION ---------
set objRootDSE = GetObject("LDAP://RootDSE")
set objSiteSettings = GetObject("LDAP://cn=" & _strSubnetName & _
"cn=subnets,cn=sites," & _
objRootDSE.Get("ConfigurationNamingContext"))
What I want to do is to modify this script to change the site assignment to multiple subnets. I have a list of subnets that need to be assigned to the same site so the site info remains unchanged.
The problem is I don`t know how to do a loop to read multiple subnets which I instert in the code or from a txt file.
Can you help me please...I am despereate because I have to do this very fast.
Many thanks in advance!
Answer Hi Raducu,
Here is the code for just reading a text file:
' Get a free file number
nFileNum = FreeFile
' Open a text file for input
Open "C:\test.txt" For Input As nFileNum
' Read the contents of the file
Do While Not EOF(nFileNum)
Line Input #nFileNum, snextline
'MsgBox snextline
Loop
' Close the file
Close nFileNum
Here I just updated with your code:
' Get a free file number
nFileNum = FreeFile
' Open a text file for input
Open "C:\subnet.txt" For Input As nFileNum
' Read the contents of the file
Do While Not EOF(nFileNum)
strNewSiteName = "<SiteName>" ' e.g. "Raleigh"
Line Input #nFileNum, strSubnetName
'MsgBox snextline
set objRootDSE = GetObject("LDAP://RootDSE")
set objSiteSettings = GetObject("LDAP://cn=" & _strSubnetName & _
"cn=subnets,cn=sites," & _
objRootDSE.Get("ConfigurationNamingContext"))