Location: List Archives

List Archives

This forum is an archive of all posts to our mailing list over the past few years.  The forum is set read only therefore to contribute you will need to join our list community.  See more info about this here.

 

When subscribed to the list you should use your standard email client to send your posts to ActiveDir@mail.activedir.org.

List Archives

Subject: [ActiveDir] Precreating sites and subnets
Prev Next
You are not authorized to post a reply.

AuthorMessages
tkern@xxxx.yyy

09/01/2005 6:03 AM  
' automksites.vbs - Creates Sites in AD using CSV input file.
' Create the input file with XLS or notepad...
'
' Format for CSV input:
' SiteName,IPAddress/mask
' Example:

' Site01,10.10.10.1/32 (For a single IP Address)
' Site02,10.10.20.0/24 (For a Class C range of Addresses)
' Site03,10.10.40.0/24
'
' Make sure the Sites, subnets, and site links do not exist for these sites
' before running this script. The script will display an error if they already exist.
'
' By dafult, this script will prompt for the input file path and name.
' See below - you can hardcode this information.

On Error Resume Next

Dim SiteName,opServerName,opDomainName

' This will prompt for the path of the input FIle...
'csvPath=InputBox("Please Enter the path to the .csv file: ")

' Or, hardcode the path as follows....
csvPath="C:\sites\SITES.csv"

csvPath="C:\sites\SITES.csv"

Set WshShell = WScript.CreateObject("WScript.Shell")

Set Root = GetObject("LDAP://RootDSE")
If Err.Number 0 Then DispFatalError ("Failed to connect to RootDSE" )
'wscript.echo "Opened RootDSE"

RootDomainNC = Root.Get("rootDomainNamingContext")
If Err.Number 0 Then DispFatalError ("Failed to retrieve Root NC.")
' wscript.echo "Opened DomainNC"

RootDNSname = ConvertDNToDNSName( RootDomainNC )
'wscript.echo "Root domain: " & RootDNSName
domsplit=Split(RootDNSname,",",-1,1)
domlen=Len(domsplit(0))
domlen=domlen-3
opDomainName=Right(domsplit(0),domlen)

ConfigurationNC = Root.Get("configurationNamingContext")
If Err.Number 0 Then DispFatalError ("Failed to retrieve Configuration NC.")
' wscript.echo "Opened ConfigNC"

ServerName = Root.Get("serverName")
If Err.Number 0 Then DispFatalError ("Failed to retrieve DN of server.")

' Wscript.echo "The name of this server is" & ServerName
namsplit=Split(ServerName,",",-1,1)
namlen=Len(namsplit(0))
namlen=namlen-3
opServerName=Right(namsplit(0),namlen)

'For i = 1 to 2
Dim fso1,f,tr1,r1,lineArray,count
Set fso1=CreateObject("Scripting.FileSystemObject")
Set f=fso1.GetFile(csvPath)
Set tr1=f.OpenAsTextStream(1,-2)
'r1=tr1.ReadLine
'Msgbox (r1)
count=0

Do While tr1.AtEndofStreamTrue
r1=tr1.ReadLine
lineArray=Split(r1,",",-1,1)
count=count + 1

SiteName = lineArray(0)
XubNet = lineArray(1) '"172.30.71.2" & i & "\/32"

'wscript.echo "LDAP://"& RooTDNSName & "/CN=" & SiteName & ",CN=Sites," & ConfigurationNC
Set SiteRoot = MyOpenDSObject("LDAP://" & RootDNSName & "/CN=" & SiteName & ",CN=Sites," & ConfigurationNC )

If Err.number = 0 Then
' wscript.echo "Site " & SiteName & " already exists..."
SiteDN = SiteRoot.Get( "DistinguishedName" )
Else
'
' Site did not exist yet, try to create it...
'
Err.Clear
'wscript.echo "Site " & SiteName & " does not already exist..."
Set SiteRoot = MyOpenDSObject("LDAP://" & RootDNSName & "/CN=Sites," & ConfigurationNC )
Set NewSite = SiteRoot.Create("site", "CN=" & SiteName)
NewSite.SetInfo

If Err.number 0 Then
DispFatalError( "Creation of site " & SiteName & " failed !" )
Else
'
' create Servers container
'
Set NewServersContainer = NewSite.Create("serversContainer", "CN=Servers")
NewServersContainer.SetInfo
If Err.number 0 Then DispFatalError( "Creation of Servers container failed !" )
Set NewServersContainer = Nothing
' create NTDS Site Settings object
'
Set NewNTDSSiteSettings = NewSite.Create("nTDSSiteSettings", "CN=NTDS Site Settings")
' Optionally Disable intersite topology generation
'
' Note that this would also disable failover...
'
NewNTDSSiteSettings.Put "Options" , 16
NewNTDSSiteSettings.SetInfo
If Err.number 0 Then DispFatalError( "Creation of NTDS Site Settings failed !" )
Set NewNTDSSiteSettings = Nothing
'
' create Licensing Site Settings object
'
Set NewSiteLicensingSettings = NewSite.Create("licensingSiteSettings", "CN=Licensing Site Settings")
NewSiteLicensingSettings.SetInfo

If Err.number 0 Then DispFatalError( "Creation of Licensing Site Settings failed !" )
Set NewSiteLicensingSettings = Nothing

LogEvent 4, "Successfully created Site " & SiteName
End If

SiteDN = NewSite.Get( "DistinguishedName" )
Set NewSite = Nothing
End If

Set SiteRoot = Nothing

' Now check if subnet already exists
'
' Before we do so, add a backslash before the '/' in the subnet,
' otherwise GetObject fails
'
'x = InStr( SubNet, "/" )
'XubNet = Left( SubNet, x-1 ) + "\" + Mid( SubNet , x )
'XubNet = "172.30.71.210\/32"
'wscript.echo "My new subnet will be:" & Xubnet
Set SubnetRoot = MyOpenDSObject("LDAP://" & RootDNSName & "/CN=" & XubNet & ",CN=Subnets,CN=Sites," & ConfigurationNC )

If Err.number = 0 Then
' wscript.echo "Subnet " & SubNet & " already exists..."
Else
'
' Subnet did not exist yet, try to create it...
'
Err.Clear

Set SubnetRoot = MyOpenDSObject("LDAP://" & RootDNSName & "/CN=Subnets,CN=Sites," & ConfigurationNC )
Set NewSubnet = SubnetRoot.Create("subnet", "CN=" & Xubnet)

NewSubnet.Put "siteObject", SiteDN
NewSubnet.SetInfo
If Err.number 0 Then
DispFatalError( "Creation of subnet " & SubNet & " failed !" )
Else
LogEvent 4, "Successfully created SubNet " & SubNet
End If
Set NewSubNet = Nothing
End If

Set SubnetRoot = Nothing

'
'MHB Skip the linking portion we will do this by hand
'

' Lastly, create sitelink linking us to the central site
'

' get name of central site from the DN of the central DC
'
'x = InStr( ServerName, ",CN=Sites," )
'If ( x = 0 ) Then
' DispFatalError( "Invalid DN of central DC, missing CN=Sites part ???" )
'Else
' xx = InStrRev( Left( ServerName , x - 1 ) , "," )
' If ( x = 0 ) Then
' DispFatalError( "Invalid DN of central DC, missing comma ???" )
' Else
' MySiteLink = Mid( ServerName , xx + 4 , x - (xx + 4) ) & "-" & SiteName

' Set SLRoot = MyOpenDSObject("LDAP://" & RootDNSName & "/CN=" & MySiteLink & ",CN=IP,CN=Inter-Site Transports,CN=Sites," & ConfigurationNC )

' If Err.number = 0 Then
' wscript.echo "SiteLink " & MySiteLink & " already exists..."
' Set SLRoot = Nothing
' Else

' create new sitelink...
'
' Err.Clear

' Dim MyList(1)

' Set IPTransportRoot = MyOpenDSObject("LDAP://" & RootDNSName & "/CN=IP,CN=Inter-Site Transports,CN=Sites," & ConfigurationNC )
' If Err.number 0 Then DispFatalError( "Failed to connect to transportRoot" )

' Set NewSiteLink = IPTransportRoot.Create("siteLink", "CN=" & MySiteLink )
' If Err.number 0 Then DispFatalError( "Creation of Site Link " & MySiteLink & " failed !" )

' MyList(0) = Mid( ServerName , xx + 1 ) ' DN of central site
' MyList(1) = SiteDN ' DN of local site
' NewSiteLink.Put "siteList", MyList

' NewSiteLink.Put "description", "NB: sitelinks are used for failover. Do not delete."
' NewSiteLink.Put "cost", 180
' NewSiteLink.Put "replInterval", 15
' We don't put a schedule on the sitelink, which means that the default
' schedule will be set (allow replication always).
'
' Reason for not taking the trouble of specifying a schedule is that
' it will only be used in a failover situtation anyway.
'
'NewSiteLink.Put "schedule", MyDefaultIPSiteLink.schedule
' NewSiteLink.SetInfo
' If Err.number 0 Then
' DispFatalError( "SetInfo of Site Link " & MySiteLink & " failed !" )
' Else
' LogEvent 4, "Successfully created SiteLink " & MySiteLink
' End If

' Set IPTransportRoot = Nothing
' Set NewSiteLink = Nothing
' End If
' End If
'End If

'Next
Loop
'wscript.echo "Domain: " & opDomainName & Chr(13) & "Server: " & opServerName & Chr(13) & "Succesfully created " & count & "Sites and Subnets" & Chr(13) & "Check AD Sites and Services to verify"
tr1.Close
wscript.quit 0

'
' Done...

'All Helper Functions here.............

'
' Convert DN (DC=a,DC=b,DC=com) to DNS (a.b.com)
'
Function ConvertDNtoDNSName( DN )

DNS = ""

i1=Instr( DN , "DC=" )
While ( i1 )
i2 = Instr( Mid( DN , i1 ), "," )
If ( i2 ) Then
DNS = DNS + Mid( DN , i1+3, i2 - (i1+3) ) + "."
DN = Mid( DN , i2 + 1 )
i1=Instr( DN , "DC=" )
Else
DNS = DNS + Mid( DN , i1+3 )
i1 = 0
End If
Wend

ConvertDNtoDNSName = DNS

End Function
Function DispFatalError( msg)

LogEvent 1, "Fatal error occurred: " & msg & Chr(13) & Chr(10) & " (" & Hex(Err.Number) & " / " & CStr(Err.Number) & " / " & Err.Description & ")"

Wscript.quit err.number

End Function

Sub LogEvent( Level, Msg )

'Wscript.Echo Msg

WshShell.LogEvent Level, Wscript.ScriptName & ": " & Msg

End Sub
' MyOpenDSObject: wrapper for OpenDSObject
' makes sure Username is filled in, otherwise uses vbNullString
'
Function MyOpenDSObject( DN )
On Error Resume Next

Set DSO = GetObject("LDAP:")

If Len( UserName ) Then
Set MyOpenDSObject = DSO.OpenDSObject( DN, UserName, Password, ADS_SECURE_AUTHENTICATION)
Else
Set MyOpenDSObject = DSO.OpenDSObject( DN, vbNullString, vbNullString, ADS_SECURE_AUTHENTICATION)
End If

Set DSO = Nothing

End Function
bdesmondUser is Offline

Posts:977

09/01/2005 7:44 AM  
Find this:

Set NewSite = SiteRoot.Create("site", "CN=" & SiteName)
NewSite.SetInfo

Change to

Set NewSite = SiteRoot.Create("site", "CN=" & SiteName)
NewSite.Put "description", "Toms Site"
NewSite.SetInfo

Find this:

Set NewSubnet = SubnetRoot.Create("subnet", "CN=" & Xubnet)

NewSubnet.Put "siteObject", SiteDN
NewSubnet.SetInfo

Change to

Set NewSubnet = SubnetRoot.Create("subnet", "CN=" & Xubnet)

NewSubnet.Put "siteObject", SiteDN
NewSubnet.Put "description", "Toms Subnet"
NewSubnet.SetInfo

In general:

Object.Put "attributeName", "Value"

All description fields are called "Description". In the MSDN Platform SDK,
you can lookup all the attributes associated with any class in the AD
schema, and vice versa.

Thanks,
Brian Desmond
brian@xxxxxxxxxxxxxxxx

c - 312.731.3132



-----Original Message-----
From: ActiveDir-owner@xxxxxxxxxxxxxxxxxx
[mailto:ActiveDir-owner@xxxxxxxxxxxxxxxxxx] On Behalf Of Kern, Tom
Sent: Thursday, September 01, 2005 2:02 PM
To: ActiveDir@xxxxxxxxxxxxxxxxxx
Subject: [ActiveDir] Precreating sites and subnets

I'm trying to run this script from MS to precreate site and subnet objects
in a test forest from a csv file.

That works fine but I also would like to add a descritpion for each subnet
from the same csv file.

How can I edit this script to do that?

Thanks. Sorry for being lazy but i'm kinda under the gun(actually this is
the IBM AD consultant's homework).

Thanks again.

List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
tkern@xxxx.yyy

09/01/2005 7:52 AM  
-----Original Message-----
From: Brian Desmond [mailto:brian@xxxxxxxxxxxxxxxx]
Sent: Thu 9/1/2005 3:43 PM
To: ActiveDir@xxxxxxxxxxxxxxxxxx
Cc:
Subject: RE: [ActiveDir] Precreating sites and subnets




>
bdesmondUser is Offline

Posts:977

09/01/2005 8:47 AM  
Dim subnetDescription



Change





SiteName = lineArray(0)

XubNet = lineArray(1) '"172.30.71.2" & i & "\/32"



To





SiteName = lineArray(0)

XubNet = lineArray(1) '"172.30.71.2" & i & "\/32"

subnetDescription = lineArray(2)



Change

Set NewSubnet = SubnetRoot.Create("subnet", "CN=" & Xubnet)



NewSubnet.Put "siteObject", SiteDN

NewSubnet.SetInfo



To



Set NewSubnet = SubnetRoot.Create("subnet", "CN=" & Xubnet)



NewSubnet.Put "siteObject", SiteDN

newSubnet.Put "description", subnetdescription

NewSubnet.SetInfo



Thanks,
Brian Desmond

brian@xxxxxxxxxxxxxxxx



c - 312.731.3132





_____

From: ActiveDir-owner@xxxxxxxxxxxxxxxxxx
[mailto:ActiveDir-owner@xxxxxxxxxxxxxxxxxx] On Behalf Of Kern, Tom
Sent: Thursday, September 01, 2005 3:51 PM
To: ActiveDir@xxxxxxxxxxxxxxxxxx
Subject: RE: [ActiveDir] Precreating sites and subnets



Thanks.

I don't want to set the descriptions of the subnets in the script but from a
csv file which has a description for every subnet

I'm having a problem reading the description from a file.

The file is - Sitename,subnet,"descritpion"

thanks again

-----Original Message-----
From: Brian Desmond [mailto:brian@xxxxxxxxxxxxxxxx]
Sent: Thu 9/1/2005 3:43 PM
To: ActiveDir@xxxxxxxxxxxxxxxxxx
Cc:
Subject: RE: [ActiveDir] Precreating sites and subnets



>
DMA81User is Offline

Posts:0

09/01/2005 8:47 AM  
Tom:

I used Robbie Allen's script to do this. You can glean from his script
the techniques for doing this. I sent you a copy under a separate email

Diane

-----Original Message-----
From: ActiveDir-owner@xxxxxxxxxxxxxxxxxx
[mailto:ActiveDir-owner@xxxxxxxxxxxxxxxxxx] On Behalf Of Kern, Tom
Sent: Thursday, September 01, 2005 11:02 AM
To: ActiveDir@xxxxxxxxxxxxxxxxxx
Subject: [ActiveDir] Precreating sites and subnets

I'm trying to run this script from MS to precreate site and subnet
objects in a test forest from a csv file.

That works fine but I also would like to add a descritpion for each
subnet from the same csv file.

How can I edit this script to do that?

Thanks. Sorry for being lazy but i'm kinda under the gun(actually this
is the IBM AD consultant's homework).

Thanks again.

List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
You are not authorized to post a reply.
Forums >ActiveDir Mail List Archive >List Archives > [ActiveDir] Precreating sites and subnets



ActiveForums 3.7
Friends

Friends

VisualClickButoton
Members

Members

MembershipMembership:
Latest New UserLatest:MrPTSai
New TodayNew Today:0
New YesterdayNew Yesterday:0
User CountOverall:5234

People OnlinePeople Online:
VisitorsVisitors:44
MembersMembers:0
TotalTotal:44

Online NowOnline Now:

Ads

Copyright 2009 ActiveDir.org
Terms Of Use