• Tag Archives AD
  • See who is logging onto your domain

    I was looking a migration from one domain to another a short while ago. Almost all the users accounts had been migrated over but there were a few hanging on.

    The migration tool wasn’t doing a great job of picking them up so I wrote a small script and added it to group policy for all servers and workstations. Now when someone logs in to the old domain a line is written to the log with their username, computer name and IP address.

    Using this the person responsible for the migration can get through the last few people on the old domain. This has saved a lot of time as before I wrote this th eprocess was very manual.


    Const ForAppending = 8
    Set WshShell = CreateObject("WScript.Shell")
    Set WshNetwork = CreateObject("WScript.Network")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("\\ServerName.DomainName.TLD\RemainingComputer\log.txt", ForAppending)
    objFile.WriteLine WshNetwork.ComputerName & "," & WshNetwork.UserName & "," & GetIpAddress
    objFile.Close

    Function GetIPAddress
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set IPConfigSet = objWMIService.ExecQuery _
    ("Select IPAddress from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'")

    For Each IPConfig in IPConfigSet
    If Not IsNull(IPConfig.IPAddress) Then
    For i = LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
    If Not Instr(IPConfig.IPAddress(i), ":") > 0 Then
    strIPAddress = strIPAddress & IPConfig.IPAddress(i) & " "
    End If
    Next
    End If
    Next
    GetIPAddress = strIPAddress
    End Function