Forum
AccountExpirationDate ile tarih verdiğimiz kullanıcıları roodsde içinde search edip disabled edebilecek bi script yazılabilirmi? Yazılar ise nasıl yazılmalıdır.
vay arkadaş kimse yapmadımı böyle bişey [:D]
Option Explicit
Const ADS_SCOPE_SUBTREE = 2
Dim oRootDSE, DNSDomain
Dim oConnection, oCommand, oRS
Dim GununTarihi
Dim HesapDN, dizin, fso
GununTarihi = Date()
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set oRootDSE = GetObject(“LDAP://RootDSE”)
DNSDomain = oRootDSE.Get(“DefaultNamingContext”)
Set oConnection = CreateObject(“ADODB.Connection”)
Set oCommand = CreateObject(“ADODB.Command”)
oConnection.Provider = “ADsDSOObject”
oConnection.Open “Active Directory Provider”
Set oCommand.ActiveConnection = oConnection
oCommand.Properties(“Page Size”) = 1000
oCommand.Properties(“Searchscope”) = ADS_SCOPE_SUBTREE
oCommand.CommandText = “SELECT distinguishedName FROM ‘LDAP://” & DNSDomain & “‘ ” & _
“WHERE objectCategory = ‘User’”
Set oRS = oCommand.Execute
oRS.MoveFirst
Do Until oRS.EOF
HesapDN = oRS.Fields(“distinguishedName”).Value
‘ExpireOlmusUserSil(HesapDN) ‘Bu satır açık iken hesap silme çalışır
ExpireOlmusUserDisabled(HesapDN) ‘Bu satır açık iken hesap disabled çalışır
oRS.MoveNext
Loop
Sub ExpireOlmusUserSil(Hesap)
Dim oUser, objOU, tarih ,Container, n
Container = “”
Set oUser = GetObject(“LDAP://” & Hesap)
On Error Resume Next
tarih = oUser.AccountExpirationDate
If tarih > “1/1/1970″ Then
If Err.Number = -2147467259 Then
Err.Clear
ElseIf tarih <= GununTarihi Then
Wscript.Echo “Silinen Hesap: ” & Hesap & ” ” &
oUser.AccountExpirationDate & ” and userhome: ” &
oUser.homeDirectory
If fso.FolderExists(oUser.homeDirectory) Then
fso.DeleteFolder oUser.homeDirectory, True
End If
dizin = Split(Hesap, “,”)
For n = 1 to UBound(dizin)
Container = Container & dizin(n) & “,”
Next
Container = Left(Container, Len(Container) – 1)
Set objOU = GetObject(“LDAP://” & Container)
objOU.Delete “user”, dizin(0)
End If
End If
On Error GoTo 0
End Sub
Sub ExpireOlmusUserDisabled(Hesap)
Dim oUser, objOU, tarih ,Container, n
Const ADS_UF_ACCOUNTDISABLE = 2
Container = “”
Set oUser = GetObject(“LDAP://” & Hesap)
On Error Resume Next
tarih = oUser.AccountExpirationDate
If tarih > “1/1/1970″ Then
If Err.Number = -2147467259 Then
Err.Clear
ElseIf tarih <= GununTarihi Then
Set objUser = GetObject _
(“LDAP://cn=” & Hesap %,ou=management,dc=fabrikam,dc=com”)
intUAC = objUser.Get(“userAccountControl”)
objUser.Put “userAccountControl”, intUAC OR ADS_UF_ACCOUNTDISABLE
objUser.SetInfo
End If
End If
End If
On Error GoTo 0
End Sub