Main Page / Index


' Adapted from
' Suggested Usage: cscript //Nologo localadmins.vbs > unauthorizedadmins.txt
' The resulting text file lists skipped computers, reachable computers and the unauthorized user
' List unauthorized local administrators across a network domain

Dim oDomain, strComputer,oLocalGroup,Item,IsOnline

' Enumerate all the computers in the domain (OU specified below)

Set oDomain = GetObject ("LDAP://OU=Desktops,OU=Computers,OU=Austin,DC=ad,DC=rmkr,DC=com")

On Error Resume Next

For Each strComputer in oDomain
      'Check if the PC is booted and online
      'If so then list the local Administrators
      If IsOnline = true Then
          Set oLocalGroup = GetObject("WinNT://" & strComputer.CN & "/Administrators,group")
          For Each item In oLocalGroup.Members
             If right(item.ADsPath,6) <> "Admins" Then     'This skips over Domain Admins, Remote Desktop Admins
                If right(item.ADsPath,6) <> "trator" Then  'This skips over Administrator
                Wscript.Echo strComputer.CN & ", " & item.ADsPath
                End If
             End If
      End If

Function PcOnline (strComputer)
'Check if the remote machine is online.
    Dim objPing,objStatus
    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
        ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputer & "'")

    For Each objStatus in objPing
        If  IsNull(objStatus.ReplySize) Then
            Wscript.Echo strComputer & " is not online"
            PcOnline = True
        End If
    Set objPing=Nothing
    Set objStatus=Nothing
End Function

Document made with Nvu