telemorgan
MIS
I have written this script to report all users that are local administrators on there machines. It tremendously helped us here at work and wanted to pass it on for others to try. I am by no means a scripting genious here so if you find something wrong or that could be improved, please let me know. I am always willing to learn.
We use Script Logic as the vechile to run this script on all machines on the network. It is set to only run once per machine.
************* BEGIN SCRIPT *********************
'*********** GET USERNAME ***************
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon"
strUserValueKey = "DefaultUserName"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,_
strUserValueKey,UserID
'*********** GET LOCAL ADMIN MEMBERS ***************
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWshNet = CreateObject("WScript.Network")
sComputer = oWshNet.ComputerName
Set oAdminGroup = GetObject("WinNT://" & sComputer & "/Administrators")
'*********** COMPARE OUTPUTS ***************
For Each oAdminUser in oAdminGroup.Members
AdminID = oAdminUser.Name
'CONVERT vars to lowercase
L_AdminID = LCase(AdminID)
L_UserID = LCase(UserID)
IF L_AdminID = L_UserID Then
Set fs = CreateObject("Scripting.FileSystemObject")
Set file = fs.OpenTextFile("\\<server>\<share>\localadmins.csv", 8, True)
file.Write L_UserID & "," & L_AdminID & vbCrLf
file.close
End If
Next
*********** END SCRIPT ****************
We use Script Logic as the vechile to run this script on all machines on the network. It is set to only run once per machine.
************* BEGIN SCRIPT *********************
'*********** GET USERNAME ***************
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon"
strUserValueKey = "DefaultUserName"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,_
strUserValueKey,UserID
'*********** GET LOCAL ADMIN MEMBERS ***************
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWshNet = CreateObject("WScript.Network")
sComputer = oWshNet.ComputerName
Set oAdminGroup = GetObject("WinNT://" & sComputer & "/Administrators")
'*********** COMPARE OUTPUTS ***************
For Each oAdminUser in oAdminGroup.Members
AdminID = oAdminUser.Name
'CONVERT vars to lowercase
L_AdminID = LCase(AdminID)
L_UserID = LCase(UserID)
IF L_AdminID = L_UserID Then
Set fs = CreateObject("Scripting.FileSystemObject")
Set file = fs.OpenTextFile("\\<server>\<share>\localadmins.csv", 8, True)
file.Write L_UserID & "," & L_AdminID & vbCrLf
file.close
End If
Next
*********** END SCRIPT ****************