Old Computer Names & IPs

Posted on 2011-04-19
Last Modified: 2012-05-11
I have inherited a rather large domain & the past network admin did not keep DNS or Active Directory clean by leaving the domain properly. In other words, when a new computer came in to be installed, he just unplugged it & put the new on in place with a different IP & NetBIOS name.

Now, that I've came along, I have noticed this. I have 6 domain controllers all are global catalog servers. I need to go through & manually delete numerous records.....instead of me manually pinging each IP or NetBIOS name to make sure it is alive or dead, is there any tool I can run that will check the domain for any computers that have not logged into the domain, lets say in a few weeks, so I can compare my list to that report & just delete the computers?
Question by:wantabe2
    LVL 11

    Expert Comment

    I believe SpiceWorks does that, its main function is for inventory purposes but it should give you the reports you need.
    LVL 20

    Expert Comment

    Maybe check the event log.
    In the security log you should see "users" with names of the form COMPUTERNAME$
    LVL 7

    Accepted Solution

    Use the dsquery command:

    dsquery computer domainroot -inactive n

    where n is number of weeks.
    You can also redirect the output to a file:

    dsquery computer domainroot -inactive n > C:\Inactive_Computers.txt

    You can also use the following vbscript (I don't remember the source) to find out the online and offline machines, you just need to run the script:
    Option Explicit
    Dim Row, XL, WshShell, FileSystem, RegularExpression, Dummy, TheNVFile, TheLine
    Dim Whacks, WhacksFound, WhacksPattern,  Flag, HostName, NBTable, PingReport, PingPattern
    Dim IPAddress, MACPattern, MACAddress, Matches, TheMatch, Match, NBCommand, TheNBTFile
    Dim IPCommand, TheIPFile, FileName, TheDate, Suggestion, Book
    Const ForReading = 1
    Row = 2
    Set XL = WScript.CreateObject("Excel.Application")
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set FileSystem = CreateObject("Scripting.FileSystemObject")
    Set RegularExpression = New RegExp
    Dummy = WshShell.Popup ("Compiling Network Address Inventory.  Please Wait...",1,"Network Address Inventory Utility",64)
    Call BuildSpreadSheet()
    WshShell.Run "Cmd.exe /c Net View > C:\Windows\Temp\NetViewList.txt", 2,True
    Set TheNVFile = FileSystem.OpenTextFile("C:\Windows\Temp\NetViewList.txt", ForReading, True)
    Do While TheNVFile.AtEndOfStream <> True
    	TheLine = TheNVFile.ReadLine
    	Whacks = "\\"
    	WhacksFound = FindPattern(TheLine, Whacks)
    	If WhacksFound Then
    		WhacksPattern = "\\\\\S*"
    		Flag = "1"
    		HostName = GetPattern(TheLine, WhacksPattern, Flag )
    		NBTable = GetNBTable(HostName)
    		MACPattern = "MAC Address = \S*"
    		Flag = "2"
    		MACAddress = GetPattern(NBTable, MACPattern, Flag )
    		PingReport = GetIPAddress(HostName)
    		PingPattern = "Reply from \S*"
    		Flag = "3"
    		IPAddress = GetPattern(PingReport, PingPattern, Flag )
    		IPAddress = Replace(IPAddress, ":", "") 
    		Call AddToSpreadSheet(HostName, IPAddress, MACAddress)
    	End If
    Dummy = WshShell.Popup ("Network Address Inventory Operation Complete",5,"Network Address Inventory Utility",64 )
    Call SaveSpreadSheet()
    Sub BuildSpreadSheet()
    	XL.Visible = True
    	Set Book = XL.WorkBooks.Add
    	XL.Columns(1).ColumnWidth = 20
    	XL.Columns(2).ColumnWidth = 20
    	XL.Columns(3).ColumnWidth = 20
    	XL.Cells(1, 1).Value = "Host Name"
    	XL.Cells(1, 2).Value = "IP Address"
    	XL.Cells(1, 3).Value = "MAC Address"
    	XL.Selection.Font.Bold = True
    	XL.Selection.Font.Size = 12
    End Sub
    Sub AddToSpreadSheet(HostName, IPAddress, MACAddress)
    	XL.Cells(Row, 1).Value = HostName
    	XL.Cells(Row, 2).Value = IPAddress
    	XL.Cells(Row, 3).Value = MACAddress
    	Row = Row + 1
    	XL.Cells(Row, 1).Select
    End Sub
    Sub SaveSpreadSheet()
    	TheDate = Date
    	TheDate = Replace(TheDate, "/", "-")
    	Suggestion = "NetAI " & TheDate & ".xls"
    	FileName = XL.GetSaveAsFilename(Suggestion)
    	If FileName <> False Then
    	End If
    End Sub  
    Function FindPattern(TheText, ThePattern)
    	RegularExpression.Pattern = ThePattern
    	If RegularExpression.Test(TheText) Then
    		FindPattern = "True"
    		FindPattern = "False"
    	End If
    End Function
    Function GetPattern(TheText, ThePattern, Flag)
    	RegularExpression.Pattern = ThePattern
    	Set Matches = RegularExpression.Execute(TheText) 
    	For Each Match In Matches
    		TheMatch = Match.Value 
    		If Flag = "1" Then TheMatch = Mid(TheMatch, 3)
    		If Flag = "2" Then TheMatch = Mid(TheMatch, 14)
    		If Flag = "3" Then TheMatch = Mid(TheMatch, 11)
    	GetPattern = TheMatch
    End Function
    Function GetNBTable(HostName)
    	NBCommand = "nbtstat -a " & HostName
    	WshShell.Run "Cmd.exe /c " & NBCommand &" > C:\Windows\Temp\NBTList.txt", 2,True
    	Set TheNBTFile = FileSystem.OpenTextFile("C:\Windows\Temp\NBTList.txt", ForReading, True)
    	GetNBTable = TheNBTFile.ReadAll
    End Function
    Function GetIPAddress(HostName)
    	IPCommand = "ping -n 1 " & HostName
    	WshShell.Run "Cmd.exe /c " & IPCommand &" > C:\Windows\Temp\IPList.txt", 2,True
    	Set TheIPFile = FileSystem.OpenTextFile("C:\Windows\Temp\IPList.txt", ForReading, True)
    	GetIPAddress = TheIPFile.ReadAll
    End Function

    Open in new window

    LVL 7

    Expert Comment

    To run the script above you should have MS Excel installed.
    LVL 15

    Expert Comment

    by:Shaik M. Sajid
    scavange stale records in dns and u'll find the approx record in DNS

    try as well as

    all the best

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Redirected folders in a windows domain can be quite useful for a number of reasons, one of them being that with redirected application data, you can give users more seamless experience when logging into different workstations.  For example, if a use…
    Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
    This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

    759 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

    8 Experts available now in Live!

    Get 1:1 Help Now