Read Computer Names From Text File With Error Handling

Questo lo definirei un "Wrapper Script", la sua funzione è quella di "avvolgere" quel codice sorgente che era stato realizzato per il semplice uso locale ed aggiungervi le funzionalità che permettono di eseguirlo su una serie di computer specificati in un elenco.

Per utilizzarlo è necessario specificare una stringa di connessione sotto alla riga '***MAKE CONNECTION*** ed inserire il codice da eseguire nella sezione '***REST OF CODE HERE***.

I dettagli relativi agli errori di connessione vengono scritti in un file di testo denominato "errors.txt".

E' possibile generare velocemente l'elenco di computer da fornire come input utilizzando lo script “List All Computers And Users Within An OU And SubOUs“.

Per un esempio di come possa essere implementato questo wrapper consultare il codice di entrambe le versioni dello script Remote IPConfig.

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
'Create a FileSystemObject
Set oFS = CreateObject("Scripting.FileSystemObject")
 
'Open a text file of computer names
'with one computer name per line
Set oTS = oFS.OpenTextFile("computers.txt")
Set oTSOut = oFS.CreateTextFile("errors.txt")
 
'go through the text file
Do Until oTS.AtEndOfStream
	'get next computer
	sComputer = oTS.ReadLine
	On Error Resume Next
 
	'***MAKE CONNECTION***
 
	If Err <> 0 Then
		oTSOut.WriteLine "Error on " & sComputer & ":" & Err.Number & ", " & Err.Description
	Else
		On Error Goto 0
 
		'***REST OF CODE HERE***
 
	End If
Loop
 
oTS.Close
oTSOut.Close

Print This Email this Twit This! Add to del.icio.us Share on Facebook Digg This! Stumble It! AddThis! Share on Segnalo Alice Share on OKNotizie

Post Metadata

Data
13 Giugno 2007

Autore
Mirko

Categorie

Lascia un commento