Reputation: 13
So, due to a recent change in structuring at the company I work for, we have gotten behind by a lot on our PC Inventory. I know how to run and export the file as CSV on every computer individually but of course that is time consuming. What I am looking for is this:
I need to place the machine names or IPs into a text file (pclist.txt) I need to create a batch file to run only on the specified PCs in pclist.txt Finally I need the info dumped to a file
The code I use on single machines is:
`systeminfo /s 'pcnameoriphere' /fo CSV >\Desktop\CurrentPC.csv`
How would I make that single machine code work on multiple machines? I know there is a way to do it but for the life of me I cannot remember it and none of the things I've read quite do what I need. Any help is fantastic. Thanks in advance!
Upvotes: 0
Views: 1491
Reputation: 24476
From a cmd prompt, do
md "%userprofile%\Desktop\Inventory"
for /f "usebackq delims=" %I in ("pclist.txt") do systeminfo /s %I /fo csv >"%userprofile%\desktop\inventory\%I.csv"`
From a batch script, double-up on the %%
signs in %%I
. It might be possible to get the results more quickly by running systeminfo
asynchronously, but I think you might have to call a batch script on each iteration like this:
batch script:
@echo off
setlocal
md "%userprofile%\Desktop\Inventory" >NUL 2>NUL
systeminfo /s %~1 /fo csv >"%userprofile%\desktop\inventory\%~1.csv"
cmd prompt:
for /f "usebackq delims=" %I in ("pclist.txt") do start /b batfile.bat %I
It gets confusing trying to redirect the output of a command launched by start /b
. Does the >
apply to start /b
itself, or to the command run by start /b
? Should the >
be escaped?
It's just easier to follow the logic by putting the redirection within a script. Then there's no ambiguity between what you intend and what cmd thinks you intend.
Upvotes: 1