HI
I found this script a few weeks ago and found it perfect til i realised it
had a few limitations. The original script was great and thanks to the guys
for there work.
The problem i'm finding is that my servers don't have the same amount of
folders as users, be default service accounts and other admin accounts etc
don't run the logon script and hence don't have a personal folder.
From what i can understand the script gets to the end of the folder list and
then stops which isn't ideal as there are many more user accounts etc that it
isn't checking.
Here is the code and i would appreciate any help as the theory of what i
need to do is confusing me already. There is a lot of tidying i can do with
the script but in the meantime i really need the script to check the entire
contents of the personal folder location and the entire contents of the
domain user list if possible
Thanks
M
-----------------------------------------
'=================
'Name: orphanV2.vbs
'Author: Tim Sullivan
'Date: 04.01.2005
'Info: This is a script to check for orphaned home folders. It reads the
name of the folder, and
' looks for a corresponding AD user account. The original concept for this
script was done by
' Alan Kaplan (alan@akaplan.com), and a lot has been borrowed from it.
'
' I made this one to look at the folder names, rather than the SID of the
folder owner. This
' worked better for me, as our home folder names are the same as our domain
usernames.
'=================
Dim AppendOut
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshShell = WScript.CreateObject ("WScript.Shell")
strDomain = WSHNetwork.UserDomain
strComputer = WSHNetwork.ComputerName
'=================
'Pre script running checks.
'===
syscheck
'===
'If Wscript is being used, script is restarted with Cscript instead.
'===
If (Not IsCScript()) Then
WshShell.Run "CScript.exe " & quote & WScript.ScriptFullName & quote, 1,
true
WScript.Quit
End If
'=================
'User input area and error checking.
'=================
strDomain = InputBox("Enter your netbios domain name here.", "Domain Name",
strDomain)
If strDomain = "" Then
quitmessage = "Domain cannot be blank. Exiting!"
Abort
End If
strTargetServer = Inputbox("Enter the target server name.", "Target Server
Name", strComputer)
If strTargetServer = "" Then
quitmessage = "Target server cannot be blank. Exiting!"
Abort
End If
strTargetServer = UCase(strTargetServer)
strStartFolder = InputBox("Enter the starting folder path. Be sure not to
put any leading or trailing slashes. Follow the example in the box.", "Search
Start Path", "C:\Documents and settings")
If strStartFolder = "" Then
quitmessage = "Starting folder cannot be blank. Exiting!"
Abort
End If
'=====
'Convert inputs to UNC
'=====
strUNCStart = "\\" & strTargetServer &"\"& Replace(strStartFolder,":","$")
WScript.Echo strUNCStart
If not objFSO.FolderExists(strUNCStart) Then
quitmessage = strUNCStart & " Not Found"
abort
End If
'====
'Prepare our output log file
'====
logsetup
'=================
'=================
'Here we get our list of folders, and call our function to actually find
'our little lost orphanes.
'====
Set objFolder = objFSO.GetFolder(strUNCStart)
Set colSubfolders = objFolder.Subfolders
For Each objSubFolder in colSubfolders
strCheckFolder = objSubFolder.name
Validate(strCheckFolder)
If strADPres = "Present" Then
EchoAndLog Date & "," & Time & "," & strUNCStart & "\" &
objSubFolder.Name & "," & "Folder/User is ok."
Else
EchoAndLog Date & "," & Time & "," & strUNCStart & "\" &
objSubFolder.Name & "," & "Folder/User is bad. User Not Found!"
End If
Next
'=================
'Functions and sub-routines
'=================
'System check functions. Checks VBScript version, and verifies WMI is
installed.
Sub syscheck()
Dim major,minor, ver, key, key2
major = (ScriptEngineMinorVersion())
Minor = (ScriptEngineMinorVersion())/10
Ver = major + minor
If err.number or ver < 5.5 then
quitmessage = "You have WScript Version " & ver & ". Please load
Version 5.5"
End If
err.clear
key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed
Components\{E92B03AB-B707-11d2-9CBD-0000F87A369E}\version"
key2 = WshShell.RegRead (key)
if err <> 0 then
quitmessage = quitmessage & "ADSI must be installed on local
workstation to continue" & vbCrLf
abort
End if
End Sub
'===
'Function to handle aborting the script.
'===
Function Abort() 'error message handler
wshShell.Popup quitmessage,0,"Abort",vbCritical
WScript.Quit
End Function
'====
'Sub routine for preparing the output log file.
'====
Sub logsetup()
On Error goto 0
Dim arTemp
logpath= wshShell.SpecialFolders("Desktop") & "\"
arTemp= Split(WScript.ScriptName,".") 'Script Name found"
logfile = logpath & artemp(0)& ".csv" 'append .CSV
'setup Log
WriteType = 2 ' forwriting 'presume for writing. Usually
done as constant...
If objFSO.FileExists(logfile) Then
retval = MsgBox("Logfile Exists, do you want to append?",vbyesno +
vbdefaultbutton1,"Old Log File")
If retval = vbyes Then
writeType = 8 'change type to append
End If
End If
On Error Resume next
Set AppendOut = objFSO.OpenTextFile(logfile, WriteType, True)
If Err <> 0 Then
MsgBox "You must close the log file!",vbcritical +
vbinformation,"Fatal Error"
WScript.Quit
End If
On Error goto 0
If WriteType = 2 Then 'only write header if new file
Appendout.writeline "Date,Time,Folder UNC,Status"
End If
End sub
'=====
'Output subroutine
'=====
Sub EchoAndLog (message)
Wscript.Echo message
AppendOut.WriteLine message
End Sub
'===
'Function for determining if CScript is being used.
'===
Function IsCScript()
If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then
IsCScript = True
Else
IsCScript = False
End If
End Function
'===
'Function for comparing foldername against AD.
'===
Function Validate(strCheckFldr)
On Error Resume Next
Dim objSAMUser
Err.Clear
Set objSAMUser = GetObject("WinNT://" & strDomain & "/" & strCheckFolder &
",user")
If Err.Number = 0 Then
strADPres = "Present"
Validate = True
Else
strADPres = "NotPresent"
Validate = False
End If
Set objSAMUser = Nothing
End Function
'================
'End Of Script
'================