Get Actual logon user, PC-Name and IP Address within Active Directory Script in Windows 2003
Hi
I want to get a script that allow me to get an upadted list when required. This list should contain the :
- Actual User login in this computer
- Last date login
- Computer Name
- the IP address.
Is there any script already existing for this and if yes then how I can use it
Thanks for help
Active DirectoryWindows Server 2003VB ScriptMicrosoft Server OS
Last Comment
venmarces
8/22/2022 - Mon
Justin Owens
You really need to include a little more info than that... For example, do you want to poll one computer, a list of computers, or all computers in your directory? Do you want to poll by OS type (workstation verses server)? How do you want to handle computers that are not on when the polling is done?
venmarces
ASKER
I want to poll all computers in my Directory of course ordered by Computer Name
Computers that are not on when the polling is done should appear in the list with a maximum of information at least computer name
Thanks
Justin Owens
So, you need a script which will query AD for all ObjectType=Computer, make a list, check DNS to resolve IP, then query each computer to get current logged in user and when they logged in and then dump that unto a 4 column CSV file? What do you want to do it there is no user logged into the computer?
That is an option, however it would mean that the "script" runs at logon, which may be a network burden for the Author or may not fulfill his needs. My assumption is that when the Author says, "when required", it isn't a constant need. Please correct this assumption if wrong. Also, is there a language preference for the script?
Justin
venmarces
ASKER
Ok, can I get real-time updates on this file ..... otherwise is there any application other then this that can show me in real-time what is the three information PC-Name, IP, UserName
That is beyond my ability. May I suggest you add this Question to the VBScript Zone? You can have it in up to three Zones and you are only currently in two.
In the logon, logoff scripts for the user and computer OU's you add a couple of lines to the logon script which appends a line to the log. Then you can just read the last line from the log for a user or pc....
so you end up with something like this along with your current scripts:
@echo off
for /f "tokens=2 delims=:" %%a in ('ipconfig ^|find "IP Address"') do call :process %%a & goto :next
:next
echo You are on subnet %subnet% with address %ipaddress%
echo %date%,%time%,%computername%,%username%,%ipaddress% >>\\server\share$\user\login\%username%.txt
echo %date%,%time%,%computername%,%username%,%ipaddress% >>\\server\share$\pc\%computername%.txt
echo %date%,%time%,%computername%,%username%,%ipaddress% >\\server\share$\lastuser\%computername%.txt
exit /b
:process
for /f "tokens=1-4 delims=." %%a in ("%1") do (set subnet=%%a.%%b.%%c)&(set host=%%d)&(set network=%%c)
set ipaddress=%subnet%.%host%
exit /b
Whether that sort of thing is an option is down to your environment and choice but is a useful little record of who logs in where and when and the last entry for each is easily parsed.
Then all you need to do to get the list of all computers and their last user is do:
type \\server\share$\lastuser\*.txt > allcomputers.csv
start excel allcomputers.csv
venmarces
ASKER
thank you for this script ... I will try it and let you know about it