VBScript code
1: Const ForReading=1
2:
3: i = 2
4:
5: strDomain = "MYDOMAIN"
6: strFile="C:\Users.txt"
7:
8: Set objShell = CreateObject("WScript.Shell")
9: Set objXL = CreateObject("Excel.Application")
10: Set objFSO = CreateObject("Scripting.FileSystemObject")
11: Set objFile=objFSO.OpenTextFile(strFile,ForReading)
12:
13: ' strDesktopFolder = objShell.SpecialFolders("Desktop")
14: objXL.Visible = True
15: objXL.Workbooks.Add
16: Set objWorksheet = objXL.Worksheets(1)
17:
18: Set objRange = objWorksheet.Range("A1","B1")
19: objRange.Font.Bold = True
20: objRange.Font.Size = 10
21: objRange.Font.ColorIndex = 2
22: objRange.Interior.ColorIndex = 9
23:
24: objworksheet.Cells(1, 1).Value = "UserName"
25: objworksheet.Cells(1, 2).Value = "GroupName"
26:
27: do While Not objFile.AtEndOfStream
28: strUserName=objFile.ReadLine
29: Set objUser = GetObject("WinNT://" & strDomain & "/" & strUsername & ",user")
30: objworksheet.Cells(i, 1).Value = objUser.name
31: For Each Group in objUser.Groups
32: objworksheet.Cells(i, 2).Value = group.name
33: i = i + 1
34: Next
35: i = i + 1
36: objworksheet.Cells(i, 1).Value = ""
37: Loop
38:
39: Set objRange = objXL.Range("A1")
40: objRange.Activate
41: Set objRange = objXL.ActiveCell.EntireColumn
42: objRange.AutoFit()
43: Set objRange = objXL.Range("B1")
44: objRange.Activate
45: Set objRange = objXL.ActiveCell.EntireColumn
46: objRange.AutoFit()
No comments:
Post a Comment