- notageek.it di Mirko Iodice - http://www.notageek.it -
Change or Create Environmental Variables On All Computers In A List
Posted By Mirko On 13 giugno 2007 @ 12:15 In Scripts | No Comments
Questo script permette di creare o modificare variabili d’ambiente su tutti i computer specificati in un elenco.
Richiede in input soltanto un semplice file di testo (computers.txt) contenente i nomi (o gli indirizzi IP) dei PC sui quali eseguire l’operazione; è possibile generare velocemente tale elenco utilizzando lo script “List All Computers And Users Within An OU And SubOUs [1]“.
Come output viene generato un unico file "results.txt" che costituisce il risultato dell'esecuzione ed ha appunto lo scopo di mettere in evidenza sia gli errori che le operazioni andate a buon fine.
Gestisce in maniera completamente autonoma le operazioni di scrittura dei risultati su file di testo, potete perciò eseguirlo indifferentemente con entrambi i motori WSH ("wscript.exe" oppure "cscript.exe") senza quindi dovervi preoccupare di reindirizzarne manualmente l'output.
Nome (strVarName) e valore (strVarValue) della variabile d’ambiente sono le uniche variabili da impostare nel codice sorgente.
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 | 'Variable name strVarName = "test_var" 'Variable value strVarValue = "test_value" '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("results.txt") 'go through the text file Do Until oTS.AtEndOfStream 'get next computer sComputer = oTS.ReadLine On Error Resume Next set objVarClass = GetObject("winmgmts:\\" & sComputer & "\root\cimv2:Win32_Environment") If Err <> 0 Then oTSOut.WriteLine "Error on " & sComputer & ":" & Err.Number & ", " & Err.Description Else On Error Goto 0 set objVar = objVarClass.SpawnInstance_ objVar.Name = strVarName objVar.VariableValue = strVarValue objVar.UserName = "<SYSTEM>" objVar.Put_ oTSOut.WriteLine "Variable created on " & sComputer End If Loop oTS.Close oTSOut.Close |
Article printed from notageek.it di Mirko Iodice: http://www.notageek.it
URL to article: http://www.notageek.it/change-or-create-environmental-variables-on-all-computers-in-a-list.html
URLs in this post:
[1] List All Computers And Users Within An OU And SubOUs: http://www.notageek.it/list-all-computers-and-users-within-an-ou-and-subous.html
[2] change_or_create_env_variables_on_all_computers_in_a_list.zip: http://www.notageek.it/wp-includes/files/change_or_create_env_variables_on_all_computers_in_a_list.zip
Click here to print.
Copyright © 2009 notageek.it. All rights reserved.