Re: User account and Personal folder mismatch script
- From: "Richard Mueller [MVP]" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 20 Jun 2005 10:38:26 -0500
Hi,
I believe you want a script that can be run by an administrator that will
check for the existence of a home folder for every user in the domain. All
of your home folders are assumed to be subfolders of:
"\\ServerName\HomeShare"
The script you posted seems to test this by enumerating all subfolders in
the assumed location, then taking the name of the subfolder and attempting
to bind to a user object (using the WinNT provider) with that same name.
First, if these are home folders, and the homeDirectory attribute of each
user has been assigned, you can check this. Using the WinNT provider:
Set objDomain = GetObject("WinNT://MyDomain")
objDomain.Filter = Array("user")
For Each objUser In objDomain
Wscript.Echo objUser.Name & ", " & objUser.HomeDirectory
Next
This can be run at a command prompt with the cscript host. You can redirect
the output to a text file (or *.csv). For example, if the VBScript is called
DocumentHome.vbs, run the following command at a command prompt:
cscript //nologo DocumentHome.vbs > Report.csv
The script above only documents if a home folder has been assigned. It does
not document if the folder exists. For that, you could use the FSO object to
test existence. For example:
Option Explicit
Dim objDomain, objUser, objFSO, blnExists
Set objDomain = GetObject("WinNT://MyDomain")
Set objFSO = CreateObject("Scripting.FileSystemObject")
objDomain.Filter = Array("user")
For Each objUser In objDomain
If objFSO.FolderExists(objUser.HomeDirectory) Then
blnExists = True
Else
blnExists = False
End If
Wscript.Echo objUser.Name & ", " & objUser.HomeDirectory _
& ", " & CStr(blnExists)
Next
This does not check if there are folders that no longer correspond to users.
I hope this helps.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--
"numbatfouram" <numbatfouram@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:67B82974-00D0-475E-9103-C612AF50F679@xxxxxxxxxxxxxxxx
> 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@xxxxxxxxxxx), 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
> '================
>
>
>
.
- Follow-Ups:
- Re: User account and Personal folder mismatch script
- From: numbatfouram
- Re: User account and Personal folder mismatch script
- References:
- User account and Personal folder mismatch script
- From: numbatfouram
- User account and Personal folder mismatch script
- Prev by Date: Lock computer
- Next by Date: How to pass parameters to vbscript
- Previous by thread: User account and Personal folder mismatch script
- Next by thread: Re: User account and Personal folder mismatch script
- Index(es):