-
Notifications
You must be signed in to change notification settings - Fork 1
/
add global group to Local group.vbs
78 lines (60 loc) · 2.87 KB
/
add global group to Local group.vbs
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'Created by: Basheer Ahmed
'ITO-GCI
'Wintel-DTS
'Email: [email protected]
'Creation date: 19/04/2007
'Overview
'Add the given global group in to the Local computers
'Input:
'Input to this script is Computers.txt file containing the server names per line one server.
'Processing:
'Upon execution of the script the given Global group is added in to all computer respective Local group.
'Output:
'The output of this script is:
'1. The given Global group is added in to all computer respective Local group.
'2. The log of the activity is stored in the AddGlobal2Local.log file
'3. For error in the execution can be viewed by using the command "findstr /i Error > Error.txt" Now open the Error.txt file and check for the errors if any.
Const strDomain = "KPMG" ' Enter your NetBIOS domain name here
Const strGlobalGroup = "GO-SG HP Support Local Power Users" ' Enter the domain global group name here
Const strLocalGroup = "Remote Desktop Users" ' Enter the local group name here
Const inFilename = "Computers.txt" ' Input file namecontaining list of computers
Const outFilename = "AddGlobal2Local.log" ' Log file namecontaining results of operation
Set iFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set inFile = iFSO.OpenTextFile(inFilename)
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set outFile = oFSO.CreateTextFile(outFilename, 8)
Set objGlobalGroup = GetObject("WinNT://" & strDomain & "/" & strGlobalGroup & ",group")
If Err.Number <> 0 Then
outFile.writeline Now & vbTab & " Error connecting to " & strDomain & "/" & _
strGlobalGroup & " --- " & Err.Description
Err.Clear
Else
Do while Not inFile.AtEndOfStream
strComputerName = inFile.ReadLine
'While Not inFile.AtEndOfStream
' arrayAccountNames = Split(inFile.Readline, vbTab, -1, 1)
' arrayAccountNames(0) contains the computer account name (to modify)
' strComputerName = arrayAccountNames(0)
' Connect to the computer's local group
Set objLocalGroup = GetObject("WinNT://" & strComputerName & "/" & strLocalGroup & ",group")
If Err.Number <> 0 Then
outFile.writeline Now & vbTab & "Error connecting to " & _
strComputerName & "/" & strLocalGroup & " --- " & Err.Description
Err.Clear
Else
' Add the global group to the local group on the computer
objLocalGroup.Add(objGlobalGroup.ADsPath)
If Err.Number <> 0 Then
outFile.writeline Now & vbTab & _
"Error adding the global group to the local group on " & _
strComputerName & " --- " & Err.Description
Err.Clear
Else
outFile.writeline (Now & vbTab & _
"Global group successfully added to local group on " & _
strComputerName & ".")
End If
End If
'Wend
Loop
End If