Black Friday = Pricewatch Bekijk onze selectie van de beste Black Friday-deals en voorkom een miskoop.

[LDAP] Oude gebruikers vinden

Pagina: 1
Acties:
  • 174 views

  • stimm
  • Registratie: Juli 2005
  • Laatst online: 11-08 19:34
Alle oude pc's in de active directory vind en disable ik met onderstaand script:

VBScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
DomainName = inputbox("Domain name")

limit = inputbox("Enter max age")
DeleteMode = Msgbox("Do you wish to run in disable 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 omited.
objCommandADSI.Properties("Size Limit")= 10000
objCommandADSI.Properties("Page Size")= 10000
objCommandADSI.Properties("Sort on") = "sAMAccountName"
objCommandADSI.CommandText = "<LDAP://" & DomainName & ">;(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 function to make sense of 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
'Are we running in delete mode or not.
if DeleteMode = vbYes then
'Ask if this machine account should be deleted from AD.
intReturn = Msgbox("Are you sure you want to disable this computer account?", vbYesNo, "Disable " & objRSADSI.Fields("name"))
'If yes then write info 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 & " -- Disabled"
objComputer.AccountDisabled = True
objComputer.SetInfo
else
txtStream.WriteLine objRSADSI.Fields("name") & ";" & dtmPwdLastSet & ";" & DiffADate & " -- Not Disabled"
End If
else
'If running in list only 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 "Done!"

'I found this function and it seems to work greate. I don't pretend to fully understand it though.
'I don't know who wrote it or I would give them credit.
Function Integer8Date(objDate, lngBias)
' Function to convert Integer8 (64-bit) value to a date, adjusted for
' local time zone bias.
Dim lngAdjust, lngDate, lngHigh, lngLow
lngAdjust = lngBias
lngHigh = objDate.HighPart
lngLow = objdate.LowPart
' Account for bug in 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 


Nu wilde ik dit ook voor users doen, dus heb ik blij alle woorden 'computer' vervangen door 'user' en dit werkte opzich wel, alleen zag ik nu gebruikers EN computers.

Hoe zou bovenstaande script aangepast moeten worden zodat ik alleen users zie? :)

  • BtM909
  • Registratie: Juni 2000
  • Niet online

BtM909

Watch out Guys...

Zie je oude users en oude computers? Dan zou je in principe toch in een keer klaar zijn? :)

Ace of Base vs Charli XCX - All That She Boom Claps (RMT) | Clean Bandit vs Galantis - I'd Rather Be You (RMT)
You've moved up on my notch-list. You have 1 notch
I have a black belt in Kung Flu.


  • RobIII
  • Registratie: December 2001
  • Niet online

RobIII

Admin Devschuur®

^ Romeinse Ⅲ ja!

(overleden)
Zanniebal schreef op woensdag 16 juli 2008 @ 11:58:
Hoe zou bovenstaande script aangepast moeten worden zodat ik alleen users zie? :)
Euh, we zijn geen afhaalbalie voor kant-en-klare oplossingen. Het is niet de bedoeling dat je hier 'effe' een bak code dumpt*, daar lomp wat in find/replaced en als het dan niet werkt onze hulp inschakelt. Dit valt onder quickfixes.
Probeer eens wat de debuggen? Debuggen: Hoe doe ik dat?

* en al helemaal niet zo'n ongeorganiseerde puinhoop. Indent je code eens, en doe wat moeite om het uberhaupt leesbaar te maken.

Voor support op 'geleende code' mag je zowieso bij de auteur zijn tenzij je een beetje je best doet de inner-workings te begrijpen. Copy/pasten en dan een topic openen is not-done ;)

[ Voor 61% gewijzigd door RobIII op 16-07-2008 12:09 ]

There are only two hard problems in distributed systems: 2. Exactly-once delivery 1. Guaranteed order of messages 2. Exactly-once delivery.

Je eigen tweaker.me redirect

Over mij


Dit topic is gesloten.