Home > Scripting > Getting a computer list for PSExec

Getting a computer list for PSExec

So those that know me will know that I do an awful lot of scripting in batch (yes, I know, time to learn something like PowerShell) and using PStools.  The most annoying part of that is getting the list of computers you might want quickly and easily.  I’ve done this a few ways in the past, but I finally came up with a very quick and dirty reusable way of doing this:

===== BEGIN – Get-ComputerList.bat =====
@echo off
if %1.==. goto SHOW_USAGE

rem remove the previous file if needed
if exist %2 del %2 /q
for /f “tokens=1 delims=\ ” %%A in (‘”net view | find “\” | find “%1″”‘) do @echo %%A >>%2
if %3.==SHOW. type %2
goto END

echo ERROR: No Parameters Given
echo USAGE: Get-ComputerList.bat ^<SEARCH-STRING^> ^<OUTPUT-NAME^> [SHOW]
echo         Search-String should not contain quotes – ie: NW- vs “NW-”
echo         Output-Name may contain a path, as long is it contained with quotes – ie: “C:\BIN\NETWISE LIST.LST”
echo        [SHOW] is optional – it will display the file after processing
echo    ie: Get-ComputerList.bat NW- NETWISE.LST SHOW
rem echo %0 %1 %2

===== END – Get-ComputerList.bat =====

I’m not suggesting that it’s anything all that impressive.  But it does give me a list of computer names without space padding (as NET VIEW gives), ignores computer descriptions, drops the \ from the beginning, etc.  It’s functional and that’s all that matters to me.  If I can save anyone some time in the future, that’s good enough for me.

This list will then work for the PSexec and other PStools formatting where it will accept @COMPUTER.LST and you may not want to do a \\* to do every computer in the domain.

Categories: Scripting
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: