WINDOWS TIP SHEET: What Sort of Admin Are You?
You'll know if you've been doing your job keeping systems in check with this nifty command prompt trick.
By Jeffery Hicks
The Windows CMD prompt is far from obsolete, especially for those of you where PowerShell simply isn't an option. One often overlooked command is SORT. Back in the golden age of command prompt administration, admins used the Sort command to manipulate text files and data sets. Run Sort /? at a command prompt to see usage and syntax.
Here are some examples of how you might use it today.
Open a command prompt and type:
type %windir%\windowsupdate.log | sort /r |more
You'll see your Windows Update log in reverse order. An even better approach might be to filter for Warnings:
find /i "Warning" %windir%\WindowsUpdate.log | sort /r |more
Run this command with PSExec against your clients to troubleshoot Windows Update problems.
Here's another idea: I have a CSV file, localadminage.csv, that contains computername, the name of the administrator account, the password age in days and when it was last changed. The file might look like this:
APP01,Administrator,"610.12",10/21/2005 4:25:05 PM
APP02,Administrator,"573.08",4/13/2005 10:24:25 AM
DC01,Administrator,"287.04",10/24/2006 8:18:44 AM
DC03,Administrator,"287.04",10/23/2006 3:51:25 PM
SQL05,Administrator,"288.79",3/13/2006 1:52:45 PM
CRM01,Administrator,"288.12",3/13/2006 1:52:41 PM
MAIL01,Administrator,"656.11",1/6/2005 2:49:34 PM
ISA01,Administrator,"250.30",2/16/2006 1:34:33 PM
MAIL02,Administrator,"253.20",5/1/2006 6:56:06 PM
I can use the Sort command to sort the file in memory. If I simply
I'll see a sorted version of the file based on the beginning of each line, which in this case will be the computer name. The original file remains untouched. You can tell the Sort command to create a new file and overwrite the original.
I recommend sending output to a new file:
Sort localadminage.csv /o localadminage-sorted.csv
If I want to sort on a different column, I need a slightly more complex command expression:
(for /f "tokens=1-5 delims=," %a in (localadminage.csv) DO @echo %c,%a) | sort /r
This should be typed as one line. When executed, the FOR command parses the file returning the third (password age) and first
The output is then sent to the SORT command which does a reverse sort. Because I've specified the password age as the first part of the line, I'll get a list of password ages and computer names with the oldest at the top. Sure you could do this in Microsoft Excel, but this is more fun and faster.
The next time you're looking to sort some data, the solution may be closer than you think.
Was this helpful? If so, Please Share it by clicking a button below..