''*** File Name: LocalAdminsCompare.vbs ***''
''*** Description: ***''
''*** - Compare local Adiminstrators against the source File ***''
''*** Requirements: ***''
''*** Parameters: ***''
''*** ServerName - Name of the Server ***''
''*** DomainName - Name of the Domain ***''
''*** SourceFile - WINS_localadmins.txt ***''
''*** Last Updated: 05/27/2008 ***''
''*********************************************************************************''
on error resume next
''*** event constants ***''
Const ForReading = 1, ForWriting = 2
Dim strComputer, strEntry1a, strEntry1b, strEntry2, strKey, strValue1, strValue2, strSubkey, ServerName, DomainName, DataCenter
Dim fso, f, f1, strM, Val, Val1, Val2, Val3, Val4, objReg, arrSubkeys, intRet1, strMsg, SourceFile, objGroup
Dim fso1, txtSourceFile, txtCompFile, strLine1, strLine2, strLine3, strLine4, strMatch, strMatch1
Set oAPI = CreateObject("MOM.ScriptAPI")
Set fso = CreateObject("Scripting.FileSystemObject")
strComputer = "."
call Begin()
function Begin()
''****************************************************************************''
''*** Check if the Parrameters are present ***''
''****************************************************************************''
strProc = "(Begin)"
call Main()
end function
function Main()
On Error Resume Next
strProc = "(Main)"
ServerName = "01hw000000"
DomainName = "DomainName"
SourceFile = "C:\Temp\AppTest.txt"
DataCenter = WScript.Arguments(3)
Set f = fso.OpenTextFile("C:\Local_Admin_details.txt", ForWriting, True)
call LocalAdminMembers()
Call AdminCompare()
f.close
fso.DeleteFile("C:\Local_Admin_details.txt")
end function
''****************************************************************************''
''*** Function creates a temp file to write Admini Group Members ***''
''****************************************************************************''
function LocalAdminMembers()
strProc = "(LocalAdminMembers)"
Dim objComp, strM
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
For Each mem In objGroup.Members
strM = replace(Right(mem.adsPath,Len(mem.adsPath) - 8),"/","\")
f.writeline strM
Next
if err.number<>0 then Call oAPI.LogScriptEvent("Local Administrator Compare", 400, 1, strProc & err.description)
end function
''****************************************************************************''
''*** Function To compare Admin group members ***''
''****************************************************************************''
function AdminCompare()
on error resume next
strProc = "(AdminCompare)"
Dim compName, retVal
retVal = InStr(ServerName,".")
if (retVal > 0) then
compName = Left(ServerName, retVal-1)
end if
Set fso1 = CreateObject("Scripting.FileSystemObject")
if fso1.fileexists(SourceFile) then
Set txtSourceFile = fso1.OpenTextFile(SourceFile, ForReading)
Do Until txtSourceFile.AtEndOfStream
strMatch1 = False
strLine3 = txtSourceFile.Readline
strLine3 = Replace(strLine3,"
strLine3 = Replace(strLine3,"
Set txtCompFile = fso1.OpenTextFile("C:\Local_Admin_details.txt", ForReading)
Do Until txtCompFile.AtEndOfStream
strLine4 = txtCompFile.Readline
If Trim(UCase(strLine4)) = Trim(UCase(strLine3)) Then
strMatch1 = True
Exit Do
End If
Loop
txtCompFile.Close
If strMatch1 <> True then
strMsg = strMsg & "::" & strLine3
End If
Loop
If strMsg <> vbempty Then
Call oAPI.LogScriptEvent("Local Administrator Compare", 403, 1, "" & vbcrlf & strProc & " " & strMsg & " accounts are present in source file " & SourceFile & " and are not present in " & ServerName & " System Administrator Group")
End IF
else
Call oAPI.LogScriptEvent("Local Administrator Compare", 404, 1, "" & vbcrlf & strProc & " Source File at the following location " & SourceFile & " Not Found")
end if
end function

No comments:
Post a Comment