0

I know I can do this with Powershell but, well, more as a project to practice my Command Prompt Scripting skills, wanna do it with a batch file. I have a txt file with ComputerNames, I want my loop to echo the name, then run SystemInfo and grab a particular line from the result.

Computers.txt reads like this:

 XPCOMPUTER1
 XPCOMPUTER2
 W7COMPUTER1
 W7COMPUTER2

My batch file looks like this:

For /F %%w IN (computer.txt) Do (echo %%w & psexec \\%%w cmd.exe & 
systeminfo | Find "Total Physical Memory:")

Which, should, list the host name, then PSexec into it and run SystemInfo and grab the Total Physical Memory, right? I thought so! But I get

%%W was unexpected at this time. 

Any thoughts?

FoxDeploy
  • 12,569
  • 2
  • 33
  • 48

2 Answers2

2

I think you need to pass systeminfo as a parameter to cmd that you launch from psexec like this:

For /F %%w IN (computer.txt) Do (echo %%w & psexec \\%%w cmd.exe /c systeminfo | Find "Total Physical Memory:")

Otherwise your just executing cmd then systeminfo, systeminfo isn't running from cmd.

Also, unless it's a typo, you wrote computer.txt in the script and you said it was called computers.txt.

I'm not sure if that will solve the problem but it's worth a shot.

Bali C
  • 30,582
  • 35
  • 123
  • 152
0

So it turns out the best approach for me to solve this was to call systeminfo directly using psexec.

For /F %%w IN (computer.txt) Do (echo %%w & psexec \\%%w systeminfo | Find "Total Physical Memory:")

Which gives me back:

Total Physical Memory:     8,126 MB

Since I've now learned PowerShell, I would attack this problem totally differently though.

ForEach ($computer in (Get-Content Computer.txt) { 
  Get-CIMInstance -ComputerName $Computer -Class Win32_ComputerSystem | `    
Select Name,@{N='RAM(MB)';E={[int]($_.TotalPhysicalMemory /1mb)}}

Which results in:

Name       RAM(MB)
----       -------
AL-1NG43Q1    8126
LOCALHOST     8126
127.0.0.1     8126
FoxDeploy
  • 12,569
  • 2
  • 33
  • 48