Localización de cuentas de computadora inactivas en AD

¿Te has preguntado cuántas cuentas de computadora inactivas hay en tu Active Directory? ¿Sabes cómo localizarlas y eliminarlas de manera efectiva? Si la respuesta es no, no te preocupes, estás en el lugar correcto. En este artículo te enseñaremos todo lo que necesitas saber sobre la localización de cuentas de computadora inactivas en AD y cómo mantener tu Directorio Activo limpio y organizado. ¡No te lo pierdas!

Cuando se trata de cuentas de computadora, desafortunadamente, parecen persistir incluso cuando las computadoras se eliminan del dominio y se retiran. Con el tiempo, la cantidad de cuentas de computadora en un Directorio activo (AD) el dominio se hará más y más grande. Es muy difícil usar las herramientas listas para usar disponibles cuando instala AD para administrar estas cuentas inactivas.

No hay procesos integrados que supervisen estos objetos obsoletos y los eliminen cuando ya no se utilicen. Así que la pregunta que te puedes estar haciendo es cómo eliminar eficazmente estos objetos inactivos. Primero, necesitamos entender qué categoriza un objeto de “computadora inactiva”. Bueno, resulta que estos Windows las computadoras restablecerán automáticamente su “contraseña de la computadora” al menos una vez cada treinta días.

Si bien este número se puede modificar, por lo general es no recomendado. Como sabemos que el atributo de antigüedad de la contraseña de la computadora se modifica automáticamente al menos una vez cada treinta días, todo lo que tenemos que hacer es consultar Active Directory y aplicar algo de lógica en el código. Hay varias maneras para extraer y manejar los datos de AD, pero creo que usar VBScript porque esta solución funciona bastante bien.

Aquí hay un ejemplo de código que consulta tu dominioen cualquier nivel (OU) de la estructura, y permite elegir la edad máxima, y ​​si se ejecuta o no en DELETE o LIST modo. Elegir 60 o 90 días para una edad máxima es Muy seguro ya que cuenta para el personal que puede estar de vacaciones o de viaje por un período prolongado de tiempo.

'***This script can be used to locate inactive computer accounts in an Active Directory domain*** 

'***The script can be run in 2 modes, DELETE and LIST***
'***DELETE mode will delete computer objects!!! Use Caution***
'***LIST mode will output to a file. However, it is easy to modify the script to***
'***write to a database.*** 

'***Set the scope of the script by using the correct starting point in the structure***
'***Change the cnPath to your needs. It can be set to the domain object level or OU***
cnPath = "OU=ouName,DC=domain,DC=com" 

'***Computers in the domain by default update their passwords once every thirty days***
'***When you run the program, this number should be greater than 30 **
'***targetting systems that may still be active.***
limit = inputbox("Enter maximum password age")
DeleteMode = Msgbox("Do you wish to run in DELETE mode?", vbYesNo)

'***Setup Log file***
Set fso = CreateObject("Scripting.FileSystemObject") 

'***The 8 in this line will append to an existing file, replace with a 2 to override***
set txtStream = fso.OpenTextFile("System.txt", 8, True)
txtStream.WriteLine "*** Ran on " & Date & " ***"

'***Setup ADSI connection and populate ADSI Collection***
Set objADOconnADSI = CreateObject("ADODB.Connection")
objADOconnADSI.Open "Provider=ADsDSOObject;"
Set objCommandADSI = CreateObject("ADODB.Command")
objCommandADSI.ActiveConnection = objADOconnADSI 

'***There is a 1000 object default if these next 2 lines are omitted***
objCommandADSI.Properties("Size Limit")= 10000
objCommandADSI.Properties("Page Size")= 10000
objCommandADSI.Properties("Sort on") = "sAMAccountName"
objCommandADSI.CommandText = "<LDAP://" & cnPath & ">;(objectClass=computer);sAMAccountName,pwdLastSet,name,distinguishedname;subtree"
Set objRSADSI = objCommandADSI.Execute 

'***Loop through record set and compare password age***
do while NOT objRSADSI.EOF
if not isnull(objRSADSI.Fields("distinguishedname")) and objRSADSI.Fields("distinguishedname") <> "" then
objDate = objRSADSI.Fields("PwdLastSet")

'***Go to the function to translate the PwdLastSet value from AD for the machine account.***
dtmPwdLastSet = Integer8Date(objDate, lngBias) 

'***calculate the current age of the password.***
DiffADate = DateDiff("d", dtmPwdLastSet, Now)

'***Is the password older than the specified age?***
if DiffADate > int(limit) then

'***Is the script running in DELETE mode?***
if DeleteMode = vbYes then

'***Ask if this machine account should be deleted from AD.***
'*** Uncomment next line and comment the following line to not be prompted for deletion of each object.***
'intReturn = vbYes
intReturn = Msgbox("Are you sure you want to DELETE this computer account?", vbYesNo, "Delete " & objRSADSI.Fields("name")) 

'***If YES, then write to log file and then DELETE it else just log it.***
If intReturn = vbYes Then
Set objComputer = GetObject("LDAP://" & objRSADSI.Fields("distinguishedname"))
strComputer = objComputer.CN

txtStream.WriteLine objRSADSI.Fields("name") & "," & dtmPwdLastSet & "," & DiffADate & ",DELETED"
objComputer.DeleteObject (0)
else
txtStream.WriteLine objRSADSI.Fields("name") & "," & dtmPwdLastSet & "," & DiffADate & ",NOT DELETED"
End If
else

'***If running in LIST mode then just write entry to log file and move on to next record.***
txtStream.WriteLine objRSADSI.Fields("name") & "," & dtmPwdLastSet & "," & DiffADate & ",LIST ONLY"
end if
end if
end if
objRSADSI.MoveNext
loop
wscript.echo "Process Completed."
 
'*** Function to convert Integer8 (64-bit) value to a date, adjusted for local time zone.***
Function Integer8Date(objDate, lngBias)
Dim lngAdjust, lngDate, lngHigh, lngLow
lngAdjust = lngBias
lngHigh = objDate.HighPart
lngLow = objdate.LowPart

'***Account for IADslargeInteger property methods.***
If lngLow < 0 Then
lngHigh = lngHigh + 1
End If
If (lngHigh = 0) And (lngLow = 0) Then
lngAdjust = 0
End If
lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow) / 600000000 - lngAdjust) / 1440
Integer8Date = CDate(lngDate)
End Function 

'***EndofScript***

Error 403 The request cannot be completed because you have exceeded your quota. : quotaExceeded

Deja un comentario