Sysinternals Homepage
Forum Home Forum Home > Sysinternals Utilities > PsTools
  New Posts New Posts RSS Feed - PSEXEC @list
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

PSEXEC @list

 Post Reply Post Reply
Author
Message
cooolvick View Drop Down
Newbie
Newbie


Joined: 28 November 2007
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote cooolvick Quote  Post ReplyReply Direct Link To This Post Topic: PSEXEC @list
    Posted: 28 November 2007 at 1:04pm
Hi all,

I would like to use PSEXEC to find the actual machine name for a list of computers
Not sure which variable I have to compare against
%computername%

Main command :
PSEXEC @list.txt test.bat

Test.bat :
Set Name = %computername%
IF "%name%" == ??????

Appreciate the help
Back to Top
Karlchen View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 June 2005
Location: Germany
Status: Offline
Points: 5131
Post Options Post Options   Thanks (0) Thanks(0)   Quote Karlchen Quote  Post ReplyReply Direct Link To This Post Posted: 28 November 2007 at 3:12pm
Hello, cooolvick.

Could you be bothered to elaborate a bit more clearly what you wish to achieve?

Quote Set Name = %computername%
This assigns the computername of the remote machine where test.bat is run to the variable "name".

(1)
Avoid spaces unless required, i.e.
Quote Set Name=%computername%

(2)
In the IF statement, with which value do you wish to compare %NAME%? Which other variable? Which hardcoded string?

(3)
How is this related to using the "@list" in any way?

Kind regards,
Karl
Back to Top
cooolvick View Drop Down
Newbie
Newbie


Joined: 28 November 2007
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote cooolvick Quote  Post ReplyReply Direct Link To This Post Posted: 28 November 2007 at 5:21pm
Could you be bothered to elaborate a bit more clearly what you wish to achieve?

Objective -Using a list of computers, connect to all machines via @list and check the hostname at the machine itself. execute some commands if the name matches else exit out.

Set Name = %computername%
This assigns the computername of the remote machine where test.bat is run to the variable "name".

(1)
Avoid spaces unless required, i.e. Set Name=%computername%
A) Point taken.

(2)
In the IF statement, with which value do you wish to compare %NAME%? Which other variable? Which hardcoded string?
a) The actual question is what should I use to compare
%name% with because PSEXEC executes the batch file locally on the machine does not pass the machine name from "list"
(3)
How is this related to using the "@list" in any way?
I wanted to do this on set of machines and thats why I am using @list

Thanks for looking at it
Back to Top
Karlchen View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 June 2005
Location: Germany
Status: Offline
Points: 5131
Post Options Post Options   Thanks (0) Thanks(0)   Quote Karlchen Quote  Post ReplyReply Direct Link To This Post Posted: 29 November 2007 at 12:58am
Hi, cooolvick.

I hope I understand you correctly now:
  • You have got a list file named "list.txt". It holds the names of your computers, 1 per line.

  • The command PSEXEC @list.txt test.bat will process this list and execute test.bat on each computer inside list.txt.

  • You assume that some of the computernames given in list.txt will not match the real computer name which you will get on the machine itself by querying the variable %COMPUTERNAME%.
    So you would like to compare the real %COMPUTERNAME% as opposed to the computername by which psexec contacted the machine and which psexec got from list.txt ?!

  • As you correctly stated psexec will not pass the computername to test.bat. - Why should it?

  • Bad news: in order to achieve your goal, you cannot simply pass the "list.txt" to psexec and have psexec process the list.

  • Good news: you can process the list.txt file yourself in a local batch file using a for loop. For each line inside the list.txt you will construct and launch a psexec commandline which will look like this:
    PSEXEC \\%%A test.bat %%A.
    "%%A" will hold exactly 1 computername as read from list.txt.
    This "%%A" will be passed to test.bat as a commandline argument. So test.bat will be able to use it for its comparison.

  • test.bat might look like this:
    Quote if "%1"=="%COMPUTERNAME%"  (
        echo Computername from listfile and real name %COMPUTERNAME%  match
    )  else  (
        echo Computername %1 and real name %COMPUTERNAME% differ.
    )
The local batch file which will process list.txt will be pretty simple:
Quote @echo off
:: Localc script: runpsexec.bat
for /F %%A in (LIST.TXT) do (
    psexec \\%%A test.bat %%A
)


HTH,
Karl



Edited by Karlchen - 29 November 2007 at 1:00am
Back to Top
cooolvick View Drop Down
Newbie
Newbie


Joined: 28 November 2007
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote cooolvick Quote  Post ReplyReply Direct Link To This Post Posted: 29 November 2007 at 11:51am
Thanks a lot..it worked like a charm

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down