Solved

Get Actual logon user, PC-Name and IP Address within Active Directory Script in Windows 2003

Posted on 2010-09-08
21
2,019 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:venmarces
  • 9
  • 7
  • 2
  • +1
21 Comments
 
LVL 31

Expert Comment

by:DrUltima
ID: 33629620
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?
0
 

Author Comment

by:venmarces
ID: 33629798

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  
0
 
LVL 31

Expert Comment

by:DrUltima
ID: 33629854
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?
0
 
LVL 5

Expert Comment

by:swap_101982
ID: 33629936
You can use BGInfo Tool from Microsoft to fulfill your requirement

http://technet.microsoft.com/en-us/sysinternals/bb897557.aspx
Once the user is logged in into system you can put BGinfo in Login script and you can export details to CSV file.
0
 
LVL 31

Expert Comment

by:DrUltima
ID: 33629993
swap,

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


0
 

Author Comment

by:venmarces
ID: 33630011

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

 
0
 

Author Comment

by:venmarces
ID: 33630055
Yes I am ok for an english script language no problem for me

I would like to get something on the server side only without any logon script adds for end users
0
 
LVL 31

Expert Comment

by:DrUltima
ID: 33630121
Sorry... by language, I meant something more along the lines of VBScript, PowerShell, etc....
0
 

Author Comment

by:venmarces
ID: 33630173
VBScript
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 

Author Comment

by:venmarces
ID: 33685937
Any response
0
 
LVL 31

Expert Comment

by:DrUltima
ID: 33691179
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.
0
 

Author Comment

by:venmarces
ID: 33691818
thats what I did but no response as well
0
 
LVL 31

Expert Comment

by:DrUltima
ID: 33692059
I requested a Moderator add it to the VBScript zone, as it is currently not in there....
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33697296
Just a thought here but what I do for a couple of sites is build a log by user and pc of who logs in and when.  Effectively along these lines:

In a shared directory with write access for all you have

\\server\share$\user\login
\\server\share$\user\logout
\\server\share$\pc
\\server\share$\lastuser

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....

echo %date%,%time%,%computername%, %username%,%ipaddress% >>\\server\share$\user\login\%username%.txt
echo %date%,%time%,%computername%, %username%,%ipaddress% >>\\server\share$\user\login\%computername%.txt

To get the IP address you can parse the ipconfig output like this:

http://scripts.dragon-it.co.uk/links/batch-get-tcpip-subnet

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

0
 

Author Comment

by:venmarces
ID: 33701832
thank you for this script ... I will try it and let you know about it
0
 
LVL 31

Expert Comment

by:DrUltima
ID: 33702345
venmarces,

Remember that is not a VBScript.  It is a Batch script.
0
 

Author Comment

by:venmarces
ID: 33716088
Can you rebuild it for one file and indicate me where I have to insert my parameteres

Thanks again
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 33716284
If you are talking about my batch file it will work as-is.  To create one file of all users is more difficult if you just want the last login as effectively that needs to be updated by all users at the same time etc.  If you just want the last login for each user then use:

@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$\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


Then add a shortcut on your desktop or whatever to a batch file as:

type \\server\share$\lastuser\*.txt > "%temp%\allcomputers.csv"
start excel "%temp%\allcomputers.csv"

Is that what you mean?

Steve
0
 

Author Closing Comment

by:venmarces
ID: 33716607
Good
0

Featured Post

Want to promote your upcoming event?

Is your company attending an event or exhibiting at a trade show soon? Are you speaking at a conference? Spread the word by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

Join & Write a Comment

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Resolve DNS query failed errors for Exchange
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…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

708 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

13 Experts available now in Live!

Get 1:1 Help Now