Imagine that you are a Service Desk technician. You need to get the computer name of the machine that a user is logged into, or has logged into in the past, or someone is requesting to find out if someone has logged into a machine or Terminal Server on a certain day or blah blah blah. Do you know how much time and resources it can take to get this info? Why not have a script to do the job for you!
After searching the intrawebz for a very long time I found some sample scripts to start with but ended up having to learn VBscript on my own. :) I came up with a very simple yet extremely powerful script intended to be applied to a GPO\Logon Script. Here is exactly what it does:
The script comes in two parts. Part one is the actual .VBS file for Logon Script called “recordlogon.vbs”. It runs at user logon and captures the Domain name, Username, Computername, and Date and Time of logon then dumps the info into TWO plain text files on a folder share that you define in the script that resides somewhere on the network. The newest entries are at the top of the file, oldest at the bottom (this was VERY hard to program by the way…). One of the files is stored as USERNAME.txt the other as COMPUTERNAME.txt where “USERNAME” is the domain logon ID of the user and “COMPUTERNAME” is the actual machine name of the computer. Both files are stored in two different folders on the network folder share. Here is a sample of the folder structure:
The USER folder holds all of the USERNAME.TXT files, the COMPUTER folder holds all of the COMPUTER.TXT files. That’s it.
Part two of the solution is a separate HTA script (which runs in a web browser) that queries against the USERNAME.TXT and\or COMPUTERNAME.TXT files on the folder share and displays the results onscreen in a text area. Need to find the name of a computer that the user logged into? No problem. Fire up the HTA script, enter the user’s domain login ID and hit submit. This will display the information from the USERNAME text file in an easy to read and easy to understand format. Need to know which users have logged into a certain computer or Terminal Server? Open the HTA script and enter the machine name and hit submit. The list of users that have logged into that computer will be displayed.
What is great about having the HTA is that you can then insert this tool into an intranet site, such as a Sharepoint team site, to control who has access to the tool, centralize management of the tool, and share it with others!
Here is a ZIP containing the VBscript package. Shoot me an email if this is useful for you! I guarantee it will be one of your most useful administrative scripts you ever use. Don’t forget to edit the scripts to match your environment! It has been generalized for public consumption.