0

Sorry about the title, I struggled to explain it in one line.

I have a simple script which gets a remote systems status, and returns the line which contains the total memory, and outputs it to a file:

systeminfo /s:HOSTNAME | findstr /C:"Total Physical Memory" >> "D:\All PCs\RAM_LOG.txt"

I have a text file which has all of the hostnames for every PC I want to check. How can I run this same command on each of the PC's in the text file, without having to make a batch file repeating this same line?

Also, If possible to also include the hostname in the log.

Thanks

UPDATE: I have come up with this, I will test it soon.

for /F "tokens=*" %%A in ("D:\All Pcs\pclist.txt") do (
    echo.   
    echo %%A >> "D:\All PCs\RAM_LOG.txt"
    systeminfo /s:%%A | findstr /C:"Total Physical Memory" >> "D:\All PCs\RAM_LOG.txt"
)
1

To get only total memory use wmic query - it is much faster.
for example:

...
wmic /NODE:"%%A" /APPEND:"D:\All PCs\RAM_LOG.txt" MEMPHYSICAL get name, TotalPhysicalMemory

But you don't need batch file, better way is use file with coma delimited hostnames

wmic /NODE:@"D:\All Pcs\pclist.txt" /APPEND:"D:\All PCs\RAM_LOG.txt" computersystem get name, TotalPhysicalMemory

You also can add global option /FAILFAST (timeout for connection to remote machine)

WMIC /FAILFAST:1000 ...
1

I managed to do this by using the following:

for /F "tokens=*" %%A in ("D:\All Pcs\pclist.txt") do (
    echo.   
    echo %%A >> "D:\All PCs\RAM_LOG.txt"
    systeminfo /s:%%A | findstr /C:"Total Physical Memory" >> "D:\All PCs\RAM_LOG.txt"
)

Where pclist.txt is a list of all host names to scan.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.