-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileScan2.vbs
More file actions
145 lines (132 loc) · 4.99 KB
/
Copy pathProfileScan2.vbs
File metadata and controls
145 lines (132 loc) · 4.99 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'******************************************************************************
'
' The following script scans a list of computers and attempts to enumerate
' the user profiles on the system. It looks for a file called LogonTime In
' the user's profile (created by the LogonTime.vbs logon script).
' The computer name, user's last logon time, profile name and profile size
' is stored in a .csv report on the C: drive. You'll need to
' be logged on with an Administrative account with privledges on the local
' machine (where the script is running) and on the machines being scanned.
'
' If you run this script with the /fast switch, it will not calculate the size
' of the user's profile, vastly speeding up the scan.
'
' Shawn Stugart
' 2-28-2006
'
' Updated on 4-11-2006
'******************************************************************************
Option Explicit
Const ForReading = 1
Dim hostname, iHelp, oShell, sReport, oReportFile
Dim sErrorBoxes, iErrors, sComplete
Dim oNet, sClients, oClientFile, sClient
Dim sProfilePath, oFSO, oFolder, dtmLogon
Dim oSubFolders, oSubFolder, sResult, oArgs, argFastScan
Dim sClientLogFile, oClientLogFile, iAnswer
CheckCScript
iErrors = 0
sClients = "C:\Clients.txt" ' Location and name of your list of client machines
sReport = "C:\ProfileScanReport-" & FormatDateTime(Date,vbLongDate) & ".csv"
Set oNet = CreateObject("WScript.Network")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oArgs = WScript.Arguments.Named
argFastScan = LCase(oArgs.Item("fast"))
sProfilePath = "X:\Documents and Settings"
On Error Resume Next
Set oClientFile = oFSO.OpenTextFile(sClients,1)
If Err.Number <> 0 Then
WScript.Echo VbCrLf & VbCrLf & "***** Error opening " & sClients & ". Make sure " _
& "you've got a list of computers to scan in " & sClients & ". *****" & vbCrLf
WScript.Quit
End If
Set oReportFile = oFSO.CreateTextFile(sReport, True)
If Err <> 0 Then
WScript.Echo VbCrLf & VbCrLf & "***** Error creating report file " & sReport _
& ". Make sure the file is not currently in use and that you have permission " _
& "to create the report in the specified directory. *****" & vbCrLf
WScript.Quit
End If
oReportFile.WriteLine("Computer,Profile,LastLogon,Size(in GB)")
Do Until oClientFile.AtEndOfStream
sClient = oClientFile.ReadLine
oNet.RemoveNetworkDrive "X:", True
If Err.Number <> 0 Then
Err.Clear
End If
oNet.MapNetworkDrive "X:", "\\" & sClient & "\C$"
If Err.Number = 0 Then
WScript.StdOut.Write(".")
Set oFolder = oFSO.GetFolder(sProfilePath)
Set oSubFolders = oFolder.SubFolders
For Each oSubFolder in oSubFolders
Select Case oSubFolder.Name
Case "All Users"
Case "Default User"
Case "LocalService"
Case "NetworkService"
Case Else
sResult = sResult & sClient & ","
sResult = sResult & oSubFolder.Name & ","
sClientLogFile = sProfilePath & "\" & oSubFolder.Name & "\LogonTime"
Set oClientLogFile = oFSO.OpenTextFile(sClientLogFile,ForReading)
If Err.Number = 0 Then
dtmLogon = oClientLogFile.ReadLine
oClientLogFile.Close
Else
dtmLogon = "NO_HISTORY"
Err.Clear
End If
If WScript.Arguments.Named.Exists("fast") Then
sResult = sResult & dtmLogon & ", FAST_SCAN"
Else
sResult = sResult & dtmLogon & "," & Round((oSubFolder.Size / 1073741824),3)
End If
oReportFile.WriteLine sResult
sResult = ""
End Select
Next
Else
WScript.StdOut.Write(".")
iErrors = iErrors + 1
sErrorBoxes = sErrorBoxes & sClient & VbCrLf
Err.Clear
End If
oNet.RemoveNetworkDrive "X:", True
Loop
If iErrors > 0 Then
sComplete = sComplete & "Could not scan the following " & iErrors & " machine(s):" & VbCrLf & VbCrLf _
& sErrorBoxes & VbCrLf & VbCrLf & "The following report has been generated: " & sReport _
& VbCrLf & VbCrLf & "Would you like to open the report now?"
Else
sComplete = sComplete & "Scanned all systems successfully." & VbCrLf & VbCrLf _
& "The following report has been generated: " & sReport _
& VbCrLf & VbCrLf & "Would you like to open the report now?"
End If
iAnswer = MsgBox(sComplete,vbYesNo)
If iAnswer = vbYes Then
oShell.Run "excel.exe " & Chr(34) & sReport & Chr(34)
Else
WScript.Quit
End If
Sub CheckCScript()
Set oShell = CreateObject("WScript.Shell")
hostname = lcase(right(WSCript.Fullname, 11))
If hostname = "wscript.exe" Then
WScript.Echo "This script requires cscript.exe"
iHelp = MsgBox("At a command line, run " & Chr(34) _
& "cscript " & WScript.ScriptFullName & Chr(34) _
& vbCrLf & vbCrLf & "Optionally, you can include the /fast " _
& "switch, in which case the size of the user's profile " _
& "will not be calculated, significantly speeding up " _
& "the scan." & vbCrLf & vbCrLf & "Do you want help?", vbYesNo)
If iHelp = vbYes Then
oShell.Run("cmd.exe")
WScript.Sleep 500
oShell.SendKeys "cscript.exe " & Chr(34) & WScript.ScriptFullName & Chr(34)
WScript.Quit
Else
WScript.Quit
End If
End If
End Sub