how to update fix and refresh computers in ou group on active directory

Posted on 2009-02-09
Last Modified: 2012-05-06
i have server 2003 as dc and i see inside active directory users and computers in ou wich inside i have all the computer name that the list don`t true ,i have computer that dont exist anymore so how i can refresh this list and correct it to take all the update computer that exist on the network?
Question by:buildingit
    LVL 6

    Accepted Solution

    You could use something like dsquery to obtain a list of workstations that have been inactive for X number of weeks:

    dsquery computer OU=MyOU,DC=MyDomain,DC=local -inactive 2

    This will return a list of computers (including their DNs) that have been inactive for 2 weeks. You could either pipe this output into something like dsrm to delete them, or manually look through the list and delete them yourself. I strongly recommend the latter.
    LVL 47

    Assisted Solution

    Here's a script that prompts you for the domain name and then you specify the cutoff age for computers to get deleted.

    rem Delete Old computer accounts from AC
    Dim OutPutFile
    Dim FileSystem
    Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
    Set OutPutFile = FileSystem.CreateTextFile("bad_comp_names.txt", True)
    On Error Resume Next
    DomainString=Inputbox("Enter the domain name","Check Active Computers","DomainName")
    if DomainString="" then
    wscript.echo "No domain specified or script cancelled."
    end if
    numDays=InputBox("What is the number of days to use as a cutoff for" & _
    "Active Computer Accounts?","Check Active Computers","XX")
    if numDays="" then
    wscript.echo "No cutoff date specified or script cancelled."
    end if
    Set DomainObj = GetObject("WinNT://"&DomainString)
    if err.number<>0 then
    wscript.echo "Error connecting to " & DomainString
    end if
    DomainObj.Filter = Array("computer")
    Wscript.echo "Computer Accounts in " & DomainString & " older than " & numDays & " days"
    For each Computer in DomainObj
    Set Account = GetObject("WinNT://" & DomainString & "/" & Computer.Name & "$")
    RefreshTime = FormatNumber((Account.get("PasswordAge"))/86400,0)
    If CInt(RefreshTime) >= CInt(numDays) Then
    'wscript.echo "**DELETE** " & Computer.Name & " Password Age is " & RefreshTime & " days."
    OutPutFile.WriteLine Computer.Name
    'Call DomainObj.Delete("Computer", Computer.Name)
    End If
    Set FileSystem = Nothing
    Set oContainer = Nothing
    set DomainObj=Nothing
    set Shell=Nothing

    Open in new window


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I have never ceased to be amazed how many problems you can encounter on a fresh install of a Windows operating system.  This is certainly case in point& Unable to complete ANY MSI installation.  This means Windows Updates are failing and I can't …
    Preface Having the need * to contact many different companies with different infrastructures * do remote maintenance in their network required us to implement a more flexible routing solution. As RAS, PPTP, L2TP and VPN Client connections are no…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now