Tuesday, August 9, 2011

Useful commands for Windows administrators

Managing a Windows 2000 Active Directory with about 100 servers, over 1500 computers and 35 sites, the following commands often helped me answer questions or solve problems.
Most commands are "one-liners", but for some I had to make an exception and go to the right directory first.

These commands could all be used in batch files, though some may need some "parsing" with FOR /F to retrieve only the required substrings from the displayed information.

Notes: (1) Commands that use external, or third party, or non-native utilities contain hyperlinks to these utilities' download sites.
(2) Replace command arguments displayed in italics with your own values.
(3) Commands or utilities that require Windows Server 2003 are marked bright blue.
Warning: Most commands on this page are very powerful tools.
Like most powerful tools they could cause a lot of damage in the hands of insufficiently skilled users.
Treat these commands like you would (or should) treat a chainsaw: with utmost care. Do not use them if you do not fully understand what they do or how they do it.
Any damage caused using these commands is completely your own responsibility.

How many users are logged on/connected to a server?

Sometimes we may need to know how many users are logged on to a (file) server, like maybe when there is a performance degradation.
At the server's console itself, with native commands only:

    NET SESSION | FIND /C "\\"

Remotely, with the help of SysInternals' PSTools:

    PSEXEC \\servername NET SESSION | FIND /C "\\"

By replacing FIND /C "\\" by FIND "\\" (removing the /C switch) you'll get a list of logged on users instead of just the number of users.