Script to List Local administrators in workstations

Por: Dr. Delso Bonfante | August 15, 2013

Olá, meu nome é Diego Luisi e no artigo de hoje demonstrarei como criar um Script em VBS para listar todos os usuários que tem privilégios de administrador nas estações de trabalho.

1) Primeiramente vamos criar um novo arquivo de texto chamado list_adm.txt

On Error Resume Next
option explicit
dim arrRealAdmins
dim objFSO,objFile
dim nomePC

'''''''''''''''''
' Configuration '
'''''''''''''''''
arrRealAdmins = Array("Administrador","Domain Admins") ' List of users that *are* supposed to be administrators; we'll ignore these people later

'''''''''''''''''''''
' End configuration '
'''''''''''''''''''''

dim adminGroup, groupMember, ret

function isPermitedAdmin(MemberName)

dim i
for i = lbound(arrRealAdmins) to ubound(arrRealAdmins)
if ucase(MemberName) = ucase(arrRealAdmins(i)) then
isPermitedAdmin = true
exit function
end if
next

isPermitedAdmin = false
end function

set adminGroup = getObject("WinNT://./Administradores, group")
for each groupMember in adminGroup.members
if not isPermitedAdmin(groupMember.name) then
ret = ret & groupMember.name & ","
end if
next

if ret = "" then
Wscript.Quit
else
ret = mid(ret, 1, len(ret)-1) ' To get rid of the last comma
set nomePC = CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("\servidornetlogonadmlocal" & nomePC.ComputerName & ".txt")
objFile.WriteLine ("The following


LOREM

dluisi

🚀 Enthusiastic about the DevOps culture and focused on Open Source technologies, I am passionate about automation, with 20 years of experience as a SysAdmin, currently working as an SRE, always open to learning new technologies and procedures to improve every day more as a professional. 👀 I’m interested in Open Source projects (Linux, CNCF, GitOps and Tools) 📚 I’m currently increasing my skills on AWS, K8S, Python, Backstage and some automations tools like Argo (CD, Autopilot, Events, Rollouts and Workflows). 🌱 Goals: Increase my programming skills. 💞 I love old and good Rock and Roll, on weekends traveling on a Harley Davidson.