Saltar a contenido

Recetas Powershell

Muestra cuántos días faltan para que caduque la contraseña del directorio activo

Para ver cuánto tiempo nos queda para que caduque la contraseña del directorio activo

Pasos:

  1. Instalar el intérprete de scripts de visual basic:
    • Ir a Windows\Inf
    • Buscar el archivo WSH.INF, dar al botón derecho del ratón y elegir Instalar
  2. Crear script listar_password.vbs (a continuación)
  3. Ejecutarlo desde línea de comandos mediante: cscript listar_password.vbs
' muestra cuántos días faltan para que caduque la contraseña del directorio activo

'========================================
' First, get the domain policy.
'========================================
Dim oDomain
Dim oUser
Dim maxPwdAge
Dim numDays

Set objNetwork = CreateObject("Wscript.Network")
'strDomainDN = "JCYL"
strDomainDN = objNetwork.UserDomain        
Set oDomain = GetObject("LDAP://" & strDomainDN)
Set maxPwdAge = oDomain.Get("maxPwdAge")

'========================================
' Calculate the number of days that are
' held in this value.
'========================================
numDays = CCur((maxPwdAge.HighPart * 2 ^ 32) + _
                maxPwdAge.LowPart) / CCur(-864000000000)
WScript.Echo "Maximum Password Age: " & numDays

'========================================
' Determine the last time that the user
' changed his or her password.
'========================================
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
'strUserDN = "CN=Roberto Hernando Velasco,OU=Power Users,OU=Economia y Empleo,OU=\<JCYL\>,DC=jcyl,DC=red"
strAdsPath = "LDAP://" & strUserDN        
Set oUser = GetObject("LDAP://" & strUserDN)    

'========================================
' Add the number of days to the last time
' the password was set.
'========================================
whenPasswordExpires = DateAdd("d", numDays, oUser.PasswordLastChanged)

WScript.Echo "Password Last Changed: " & oUser.PasswordLastChanged
WScript.Echo "Password Expires On: " & whenPasswordExpires

'========================================
' Clean up.
'========================================
Set oUser = Nothing
Set maxPwdAge = Nothing
Set oDomain = Nothing

WScript.Echo "Done"

Última actualización: August 15, 2021