1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| Dim strSiteRDN, strSiteLinkRDN, strSiteLinkType
Dim objRootDSE, strConfigurationNC, strSubnetsContainer
Dim objSitesContainer, objSite, strSiteLinkPath, objSiteLink
Dim strFile, objFSO, objFile, strLine, arrValues
Const ADS_PROPERTY_APPEND = 3
Const ForReading = 1
' Specify text file of comma delimited parameters.
strFile = "c:\Script\SubnetInfo.csv"
' Open the file for reading.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
' Bind to Sites container. Do this just once.
Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")
strSiteObjectDN = strSiteObjectRDN & ",cn=Sites," & strConfigurationNC
strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites" & strConfigurationNC
Set objSubnetsContainer = GetObject("LDAP://cn=Subnets,cn=Sites,cn=configuration,DC=mondomaine,DC=net")
' Read the text file.
Do Until objFile.AtEndOfStream
strLine = Trim(objFile.ReadLine)
strLine = Replace(strLine, """", "")
arrValues = Split(strLine, ",")
If (UBound(arrValues) = 3) Then
strSubnetRDN = arrValues(0)
strSiteObjectRDN = arrValues(1)
strDescription = arrValues(2)
strLocation = arrValues (3)
' Create the Subnet object.
Set objSubnet = objSubnetsContainer.Create("subnet", strSubnetRDN)
objSubnet.Put "siteObject", strSiteObjectDN
objSubnet.Put "description", strDescription
objSubnet.Put "location", strLocation
objSubnet.SetInfo
Else
Wscript.Echo "Invalid line: " & strLine
End If
Loop
' Clean up.
objFile.Close |
Partager