Welcome to Scripting Forums Sign in | Join | Help
in Search

Accessing Active Directory "Deleted Objects" with Powershell

Last post 12-22-2007, 7:30 AM by jturnervbs. 0 replies.
Sort Posts: Previous Next
  •  12-22-2007, 7:30 AM 29084

    Accessing Active Directory "Deleted Objects" with Powershell

    I gave up on trying to get "Deleted Object" info with VBScript and figured out (the basics) on how to get AD Deleted Object info using Powershell. 

    Thought you might be interested. 

    Note, I still prefer VBScript over Powershell but I'm finding there are some things you just can't do with VBScript, so it's nice to know that Powershell may be capable of accomplishing those tasks.

    I'm still working on fine tuning this code and researching some performance issues.  If I can get all of this performing well I may put together a Scripting Pro VIP article on this.  Currently I'm finding that Powershell used in this fashion with Excel is very slow.  So heads up on that.

    Let me know if you think you'd be interested in reading more about this.  PS, you have to be an Administrator to access this info.

    Here's the down and dirty Powershell code:

    $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
    $root = $dom.GetDirectoryEntry()
    $root.psbase.AuthenticationType=[System.DirectoryServices.AuthenticationTypes]::FastBind
    $root.psbase.path ="LDAP://cn=Deleted Objects," + $root.distinguishedname
    $search = [System.DirectoryServices.DirectorySearcher]$root
    $search.Filter = "(isDeleted=TRUE)"
    $search.tombstone = $true
    $search.SearchScope = [System.DirectoryServices.SearchScope]::OneLevel
    $result = $search.Findall()
    #$result

    $x = New-Object -comobject Excel.Application
    $x.Visible = $True
    $y = $x.Workbooks.Add()
    $z = $y.Worksheets.Item(1)
    $row = 1
    for ($a = 0; $a -le $result.count; $a++) {
    $z.Cells.Item($row,1) = $($result[$a].properties.distinguishedname)
    $z.Cells.Item($row,2) = $($result[$a].properties.dscorepropagationdata)
    $z.Cells.Item($row,3) = "$($result[$a].properties.objectsid)"
    $z.Cells.Item($row,4) = $($result[$a].properties.whencreated)
    $z.Cells.Item($row,5) = $($result[$a].properties.samaccountname)
    $z.Cells.Item($row,6) = $($result[$a].properties.name)
    $z.Cells.Item($row,7) = $($result[$a].properties.usnchanged)
    $z.Cells.Item($row,8) = $($result[$a].properties.isdeleted)
    $z.Cells.Item($row,9) = $($result[$a].properties.instancetype)
    $z.Cells.Item($row,10) = "$($result[$a].properties.objectguid)"
    $z.Cells.Item($row,11) = $($result[$a].properties.cn)
    $z.Cells.Item($row,12) = $($result[$a].properties.objectclass)
    $z.Cells.Item($row,13) = $($result[$a].properties.usncreated)
    $z.Cells.Item($row,14) = $($result[$a].properties.useraccountcontrol)
    $z.Cells.Item($row,15) = $($result[$a].properties.lastknownparent)
    $z.Cells.Item($row,16) = $($result[$a].properties.whenchanged)
    $z.Cells.Item($row,17) = $($result[$a].properties.adspath)
    $row++
    }
    $y.SaveAs("C:\temp\DeletedObjects.xls")

View as RSS news feed in XML
SPONSORED LINKS FEATURED LINKS

Free Download –VS 2008 TrainingExperts Ken Getz & Robert Green plus labs, code, courseware Maximize speed, performance and reliablity of your PCs and servers—automatically!Speed Up Your PC! Try Diskeeper 2008 with InvisiTasking Free Now! Register for SolarWinds VM MonitorGet X-Ray Vision into Your ESX Servers with SolarWinds FREE VM Monitor GoGrid Offers FREE Trial for Windows Cloud ServersDeploy Windows Server 2003 and 2008 with free load balancing through GoGrid’s award winning web-based GUI – all in less than 5 minutes Order Your SQL Fundamentals CD Today! Learn how to use SQL Server, understand Office integration techniques and dive into the essentials of SQL Express and Visual Basic with this free SQL Fundamentals CD. How healthy is your Exchange Server? Find out Now!Automatic Exchange Server Maintenance helps prevent disasters and improves performance. Download a FREE Exchange Server analysis tool. You've Deployed SharePoint...Now What?This one-day free online conference delivers the technical knowledge needed to kick MOSS up a notch. In one information-packed day, independent SharePoint experts will present practical, real-world information and provide take-away, ready-to-use solutions Ease Your Scripting Pains with the Flexibility of PowerShell!Paul Robichaux equips you with PowerShell basics in 3 introductory lessons, each followed by live Q&A—all on your own computer! Register today! What Would You Do If You Ran Microsoft?ITTV's 2008 inaugural video contest, "If I Ran Microsoft..." is your chance to tell it like it is. Be goofy or be serious, but don"t miss this chance to have fun, win prizes, and go viral in a major way. Maximize Your SharePoint InvestmentThis web seminar discusses how true bi-directional replication of SharePoint content from one server to another enables branch offices to maintain access to current SharePoint content. Rock Your Knowledge, and Compete with Friends and Colleagues!Are you the Web Application Performance Guru in your office? It's time to have fun! Download now to access the crossword puzzle. Challenge yourself and complete this fun activity!

 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing