Wednesday, July 17, 2013

The Poor Man's Site Management Tools

If you're an "I.T. Guy" you know about PS Tools from SysInternals (now part of Microsoft). These tools offer great power for remote administration and with great power comes great responsibility so please be aware of whose life and livelihood you're affecting when you perform remote tasks. There are some built-in tools that can make life easy, as long as you've prepared for it.

To prepare for this, your PCs should be similar, if not the same. The consistency of the PCs is a huge benefit, but don't let minor variations bother you, simply ensure that the account (AD account and local support account) are available and consistent across your organisation. I don't recommend giving your helpdesk staff "local admin" capabilities, but find that giving them an alternate account with super-powers that is not their default login is best. For example, John Doe's account is jdoe, but his admin account may be a-jdoe. Only the "a-" User ID has the abilities to add a computer to the domain, and is the local admin for user PCs. Separating this out offers some degree of auditing and not sharing passwords on these premium service accounts.

Generic accounts are NEVER preferred. Your account is your identity, you should never impersonate anyone, nor should you share your identity (user ID and credentials) with others.

Okay, sorry about the security lecture.

What I want to show you is how I use Windows tools to gather and distribute information to people across my office.

Collecting PC names:
@echo off
SET IPRoot=172.25.117.
SET iSubNet=1
IF NOT EXIST newPCList.csv ECHO "COMPUTERNAME", "MAC Address", "IP Address" > newPCList.csv
IF NOT EXIST newPCList.txt ECHO COMPUTERNAME > newPCList.txt
IF NOT EXIST newPCList.txt ECHO ============ > newPCList.txt
:START
SET /A iSubNet=%iSubNet% + 1
Echo Checking IP [%IPRoot%%iSubNet%]:
SET IPAddress=%IPRoot%%iSubNet%
NBTSTAT -A %IPRoot%%iSubNet% > fpcdata.txt
::echo Err: %ERRORLEVEL%
FOR /F "tokens=1,2,3,4* delims=<> " %%a in (fpcdata.txt) do call :subPI %%a %%b %%c %%d %%e
IF /I 0%iSubNet% LSS 255 GOTO START
GOTO :END
:subPI
SET varX=%2
SET varY=%1
set varW=%3
::ECHO DATA: 1:%1 2:%2 3:%3 4:%4 5:%5
::IF "%varX%"=="20" echo COMPUTERNAME: %varY% %IPAddress%
IF "%varX%"=="20" SET CN=%varY%
IF "%varX%"=="Address" echo %CN% [%varW%/%IPAddress%]
IF "%varX%"=="Address" echo %CN%, %varW%, %IPAddress% >> newPCList.csv
IF "%varX%"=="Address" echo %CN% >> newPCList.txt
::IF "%varX%"=="Address" pause
goto :eof
:END
goto :eof
This .cmd (batch) file scans the IP Address range my PCs are on, collects some essential information from the NBTSTAT.EXE program, and creates a .txt file and .csv listing the PCs found. This expects the PCs to be on, of course, but the result is a fairly accurate count of PCs on the network and a workable list to go from.

So, I have a list of PCs. What do I do now?

Having a list is not the end of it, in fact you may need to run that routine over a few days then remove the duplicates from the list to get an accurate picture. Either way, after the list is complete you need to be able to work with all of those PCs. I have a batch file for that:
@echo off
SET target=\\%1\C$\ITAdmin\
FOR /F "skip=1" %%a in (newPCList.txt) do call :updatePC %%a
goto :eof
:updatePC
IF NOT EXIST \\%1\C$ GOTO :PCNotFound
IF EXIST \\%1\C$\Users GOTO :Win7
:WinXP
echo %1 is WinXP
goto :doUpdate
:Win7
echo %1 is Win7
goto :doUpdate
:doUpdate
IF NOT EXIST 
%target% MKDIR %target%
IF NOT EXIST 
%target%scripts MKDIR %target%scripts
ROBOCOPY deployme\setup 
%target%setup /XO /E /Z /MIR /R:3 /W:5
ROBOCOPY deployme\scripts %target%scripts /XO /E /Z /MIR /R:3 /W:5
REG ADD \\%1\HKLM\Software\Microsoft\Windows\CurrentVersion\Run /v PCInventory /f /d "C:\ITAdmin\scripts\WritePCInfo.vbs"
ECHO %DATE% %TIME%> 
%target%LastUpdate.txt
goto :eof
:PCNotFound
echo %DATE% %TIME%, %1 >> PCFailed.LOG
echo PC inaccessible: %1
goto :eof
(more to come...)

No comments:

There is no individual ownership when you are part of a team, it's the sum of the parts that makes you the RESILIENT team you need to be.