Subnet-Importer Script

Musstest Du schon einmal so richtig viele Subnetze in „AD Standorte und -Dienste“ erstellen, obwohl eigentlich alle schon in einer CSV-Datei vorhanden gewesen wären? Dann ist dieses Script das Richtge für Dich!

Exportiere einfach Dein Excel-File in ein CSV-Format – sorge dabei dafür, dass die Spalte „Standort“ und „Subnet“ vorhanden ist. Die Standorte müssen hierbei schon existieren. Dann rufe das Script entsprechend der Parameter-Struktur auf und Voila: Die Subnetze sind da, ohne, dass diese mühsam erfasst hätten werden müssen!

Nachfolgend sind alle Parameter davon aufgelistet:

*************************************************************************
*************************************************************************
*************************************************************************
*************************************************************************
****             SubnetImporter 1.0 by iTrain GmbH 2010              ****
****                           www.itrain.ch                         ****
*************************************************************************
*************************************************************************
*************************************************************************
*************************************************************************

DESCRIPTION:

Imports subnets from a text file in CSV format and links them to an
existing site in Active Directory.
PREREQUISITES:

The site names specified in the import file should already be in place.

The format of the CSV file should be like this:

1. column: IP subnet (e.g. ‚192.168.1.0/24‘)
2. column: name of the existing site in AD

PARAMETERS:

– FileName: The name of the import file
EXAMPLES:

– Import all subnets from a text-file:
  SubnetImporter /FileName:Links.txt

*************************************************************************

Hier das Script dazu (welches einfach mittels „CScript“ aufgerufen werden muss):

‚////////////////////////////////////////////////////////////////////////////
‚//
‚//
‚// Title: iTrain Migration Toolkit
‚// Author: a.pflaum@itrain.ch
‚// Created: 02/11/2010
‚//
‚// Purpose: 
‚//  
‚//  
‚// Revision:
‚////////////////////////////////////////////////////////////////////////////

‚ Definition of constants
Const adOpenStatic = 1
Const ForReading = 1
Const Forwriting = 2
Const ForAppending = 8
Const ADS_FAST_BIND = 32
‚ Handle command line arguments
Dim ArgumentList : Set ArgumentList = ProcessCommandLineArguments()
Dim szFileName   : szFileName       = ArgumentList.Item(„FileName“)

‚ *********************************************************************************************************
‚ *********************************************************************************************************
‚ *********************************************************************************************************
‚ *********************************************************************************************************
‚ PROCESSING **********************************************************************************************
‚ *********************************************************************************************************
‚ *********************************************************************************************************
‚ *********************************************************************************************************
‚ *********************************************************************************************************

‚ *********************************************************************************************************
‚ *********************************************************************************************************
‚ If you like to import the subnets…
‚ *********************************************************************************************************
‚ *********************************************************************************************************
WScript.Echo(„*************************************************************************“)
WScript.Echo(„*************************************************************************“)
WScript.Echo(„*************************************************************************“)
WScript.Echo(„****                   Start of import procedure                     ****“)
WScript.Echo(„*************************************************************************“)
WScript.Echo(„*************************************************************************“)
WScript.Echo(„*************************************************************************“)
WScript.Echo(„“)
WScript.Echo(„- Start reading the input file“)
WScript.Echo(„- Processing subnets“)

Set objFSO = CreateObject(„Scripting.FileSystemObject“)

‚ Check, whether the file exists
If objFSO.FileExists(szFileName) = False Then
 WScript.Echo(„!!! The filename specified in the arguments was not found !!!“)
 WScript.Quit(-1)
End If

‚ Open the file
Set objCSVFile = objFSO.OpenTextFile(szFileName,1)

WScript.Echo(„- Input file was opened successfully!“)
WScript.Echo(„“)
WScript.Echo(„*************************************************************************“)

Set objRootDSE = GetObject(„LDAP://RootDSE„)
strConfigurationNC = objRootDSE.Get(„configurationNamingContext“)
 
On Error Resume Next

Do While Not objCSVFile.AtEndOfStream 

 arrStr = Split(objCSVFile.ReadLine,“;“)

 strSubnetRDN     = „cn=“ & arrStr(0)     ‚“cn=192.168.1.0/26″
 strSiteObjectRDN = „cn=“ & arrStr(1)     ‚“cn=Ga-Atl-Sales“

 strSiteObjectDN = strSiteObjectRDN & „,cn=Sites,“ & strConfigurationNC
 
 strSubnetsContainer = „LDAP://cn=Subnets,cn=Sites,“ & strConfigurationNC
 
 Set objSubnetsContainer = GetObject(strSubnetsContainer)
 
 Set objSubnet = objSubnetsContainer.Create(„subnet“, strSubnetRDN)
 objSubnet.Put „siteObject“, strSiteObjectDN
 objSubnet.SetInfo

 WScript.Echo(„- Subnet ‚“ & arrStr(0) & „‚ in site ‚“ & arrStr(1) & „‚ created successfully!“)

Loop
WScript.Echo(„“)
WScript.Echo(„*************************************************************************“)
WScript.Echo(„*************************************************************************“)
WScript.Echo(„*************************************************************************“)

If vError = True Then
 WScript.Echo(„****                  Import completed with errors!                  ****“)
Else
 WScript.Echo(„****                  Import successful completed!                   ****“)
End If 

WScript.Echo(„*************************************************************************“)
WScript.Echo(„*************************************************************************“)
WScript.Echo(„*************************************************************************“)

‚ *********************************************************************************************************
‚ *********************************************************************************************************
‚ *********************************************************************************************************
‚ *********************************************************************************************************
‚ FUNCTIONS ***********************************************************************************************
‚ *********************************************************************************************************
‚ *********************************************************************************************************
‚ *********************************************************************************************************
‚ *********************************************************************************************************
‚ Returns a dictionary object
‚ containing the named arguments and values that were passed in
Function ProcessCommandLineArguments()

 Dim szFileName    : szFileName    = „“

 ‚ Check if this is cscript. If not, print an error and bail out

 If UCase(Right(WScript.FullName,11)) = „WSCRIPT.EXE“ Then
  WScript.Echo „You must use cscript.exe to execute this script.“
  WScript.Quit(-1)
 End If

 If WScript.Arguments.Length = 0 Then
  strUsage = „“
  strUsage = strUsage & „*************************************************************************“ & vbCrLf
  strUsage = strUsage & „*************************************************************************“ & vbCrLf
  strUsage = strUsage & „*************************************************************************“ & vbCrLf
  strUsage = strUsage & „*************************************************************************“ & vbCrLf
  strUsage = strUsage & „****             SubnetImporter 1.0 by iTrain GmbH 2010              ****“ & vbCrLf
  strUsage = strUsage & „****                           www.itrain.ch                         ****“ & vbCrLf
  strUsage = strUsage & „*************************************************************************“ & vbCrLf
  strUsage = strUsage & „*************************************************************************“ & vbCrLf
  strUsage = strUsage & „*************************************************************************“ & vbCrLf
  strUsage = strUsage & „*************************************************************************“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  strUsage = strUsage & „DESCRIPTION:“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  strUsage = strUsage & „Imports subnets from a text file in CSV format and links them to an“ & vbCrLf
  strUsage = strUsage & „existing site in Active Directory.“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  strUsage = strUsage & „PREREQUISITES:“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  strUsage = strUsage & „The site names specified in the import file should already be in place.“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  strUsage = strUsage & „The format of the CSV file should be like this:“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  strUsage = strUsage & „1. column: IP subnet (e.g. ‚192.168.1.0/24‘)“ & vbCrLf
  strUsage = strUsage & „2. column: name of the existing site in AD“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  strUsage = strUsage & „PARAMETERS:“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  strUsage = strUsage & „- FileName: The name of the import file“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  strUsage = strUsage & „EXAMPLES:“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  strUsage = strUsage & „- Import all subnets from a text-file:“ & vbCrLf
  strUsage = strUsage & “  SubnetImporter /FileName:Links.txt“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  strUsage = strUsage & „*************************************************************************“ & vbCrLf
  strUsage = strUsage & „“ & vbCrLf
  WScript.Echo(strUsage)
  WScript.Quit(-1)
 End If
 
 Dim Result : Set Result = CreateObject(„Scripting.Dictionary“)

 ‚ get the parameter(s)
 If WScript.Arguments.Named.Exists(„FileName“) Then
  szFileName = WScript.Arguments.Named(„FileName“)
 End If
 
 Result.Add „FileName“, szFileName

 Set ProcessCommandLineArguments = Result

End Function

Viel Spass damit!

VN:R_U [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Schreib einen Kommentar