#192868 - 2009-03-13 02:54 PM
Deleting AD Accounts
|
HarrowCactus
Fresh Scripter
Registered: 2006-04-12
Posts: 10
Loc: United Kingdom
|
I have a requirement to delete all Disabled accounts and the Disabled account's Home drive, share and profile.
At present there are over 300 Disabled accounts on the Domain.
Does anyone have a way of doing this?
Any help would be great.
|
Top
|
|
|
|
#192871 - 2009-03-13 03:59 PM
Re: Deleting AD Accounts
[Re: Lonkero]
|
HarrowCactus
Fresh Scripter
Registered: 2006-04-12
Posts: 10
Loc: United Kingdom
|
The last time I had to do this I used a Product called Hyena, to create a report which I then saved as text files One for each of the profile path, home directory.
AS the Home directory and share name is the same I used share.vbs to remove the share then delete the directory using the "rmdir" command.
Then after all was deleted I went back to Hyena and deleted the accounts
|
Top
|
|
|
|
#193659 - 2009-05-04 01:35 PM
Re: Deleting AD Accounts
[Re: Mart]
|
WagnerJu
Fresh Scripter
Registered: 2009-03-20
Posts: 6
Loc: Germany
|
This code solves some of my problems. But what other fields are there to be read. I need something like last logon time, last time of password change, when was the user account created and so on. Is there a list available of all attributes I can use?
kind regards
Jürgen
|
Top
|
|
|
|
#193661 - 2009-05-04 02:26 PM
Re: Deleting AD Accounts
[Re: WagnerJu]
|
Gargoyle
MM club member
   
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
To see the available attributes you can get a LDAP browser (such as Softerra), or use the code below that was done by either Allen or Apronk.
Break ON
$=SetOption("WrapAtEOL","ON")
$usr = @UserID
$logf = "c:\scripthome\logs\ad_props.txt"
$cnusr = TranslateName($usr)
$usrnfo = GetObject("LDAP://" + $cnusr)
$usrclas = GetObject($usrnfo.schema)
$fso = CreateObject("Scripting.FileSystemObject")
$log = $fso.OpenTextFile($logf, 8, 1)
$log.WriteLine("Mandatory Properties:")
$log.WriteLine("---------------------")
$log.WriteLine("")
For Each $prop in $usrclas.MandatoryProperties
If Not InStr($prop,"-")
$= Execute("$$Type=VarTypeName($$usrnfo."+$prop+")")
$= Execute("$$Value=$$usrnfo."+$prop)
If $type <> "Object" And $type <> "Variant[]"
WriteLog($prop,$type,$value)
Else
WriteLog($prop,$type)
EndIf
Else
WriteLog($prop,"N/A")
EndIf
Next
$log.WriteLine("")
$log.WriteLine("Optional Properties:")
$log.WriteLine("--------------------")
$log.WriteLine("")
For Each $prop in $usrclas.OptionalProperties
If Not InStr($prop,"-")
$= Execute("$$Type=VarTypeName($$usrnfo."+$prop+")")
$= Execute("$$Value=$$usrnfo."+$prop)
If $type = "Variant[]"
For Each $obj in $Value
WriteLog($prop,$type,$obj)
Next
EndIf
If $type <> "Object" And $type <> "Variant[]"
WriteLog($prop,$type,$value)
Else
WriteLog($prop,$type)
EndIf
Else
WriteLog($prop,"N/A")
EndIf
Next
$log.Close
Function WriteLog($LineToWrite,$sType,Optional $sValue)
If Len($LineToWrite) < 8
$log.WriteLine($LineToWrite + " " + $sType + " " + $sValue)
EndIf
If Len($LineToWrite) >= 8 And Len($LineToWrite) < 16
$log.WriteLine($LineToWrite + " " + $sType + " " + $sValue)
EndIf
If Len($LineToWrite) >= 16 And Len($LineToWrite) < 24
$log.WriteLine($LineToWrite + " " + $sType + " " + $sValue)
EndIf
If Len($LineToWrite) >= 24 And Len($LineToWrite) < 32
$log.WriteLine($LineToWrite + " " + $sType + " " + $sValue)
EndIf
If Len($LineToWrite) >= 32
$log.WriteLine($LineToWrite + " " + $sType + " " + $sValue)
EndIf
EndFunction
Function TranslateName($NameToTranslate)
Dim $NameTranslate
$NameTranslate = CreateObject("NameTranslate")
$NameTranslate.Init(3,"")
$NameTranslate.Set(3, @LDOMAIN + "\" + $NameToTranslate)
$TranslateName = $NameTranslate.Get(1)
EndFunction
_________________________
Today is the tomorrow you worried about yesterday.
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 581 anonymous users online.
|
|
|