prakash82x
I have a script which gathers some information by Querying WMIC from local server,
Now I want this to query from Remote servers by reading server names from an input file i.e. servers.txt and then generating output as mentioned along with the server name against which the query has been run.
Code: Select all
@echo off
set "OutputFile=test.csv"
for /F "skip=2 tokens=2-3 delims=," %%A in ('wmic computersystem get manufacturer^,model /FORMAT:csv') do (
set "Manufacturer=%%A"
set "Model=%%B"
)
for /F "skip=2 tokens=2 delims=," %%A in ('wmic bios get serialnumber /FORMAT:csv') do (
set "Serial=%%A"
)
echo %Manufacturer%, %Model%, %Serial%>>%OutputFile%
#2 06 Aug 2013 19:03
sonda
Where is the question?
----------------------------
#3 06 Aug 2013 23:37
Giacomo
I guess: "How to improve my script to work from a remote server?"sonda wrote:
Where is the question?
----------------------------
#4 07 Aug 2013 09:25
bluesxman
As is so often the case, the answer is in the manual.
You can do this with the /node switch:
Code: Select all
C:\>wmic /node /?
NODE - Specify which servers the alias will operate against.
USAGE:
/NODE:<machine id list>
NOTE: <machine id list> ::= <@filename | machine id> | <@filename | machine id> <,machine id list>
NOTE: Enclose the switch value in double quotes, if the value contains special characters like '-' or '/'.
Last edited by bluesxman (07 Aug 2013 09:26)
cmd | *sh | ruby | chef
----------------------------
#5 08 Aug 2013 16:25
prakash82x
(Sorry if I could not post my question correctly)bluesxman wrote:
As is so often the case, the answer is in the manual.
You can do this with the /node switch:
So you could just point it at your servers.txt file.Code: Select all
C:\>wmic /node /? NODE - Specify which servers the alias will operate against. USAGE: /NODE:<machine id list> NOTE: <machine id list> ::= <@filename | machine id> | <@filename | machine id> <,machine id list> NOTE: Enclose the switch value in double quotes, if the value contains special characters like '-' or '/'.
Currently there is no wmi /node:servername syntax defined in the script so it is generating output from the local machine only on which it is executed, I want it to loop through the whole script and run against each remote server listed in the input file (need to define one text file containing target servers) and write the result in test.csv along with the node name/target server in a column.
----------------------------
#6 08 Aug 2013 16:28
prakash82x
Correct I want to run the script against remote servers and the server names should be picked up from a text file ..Giacomo wrote:
sonda wrote:
Where is the question?
I guess: "How to improve my script to work from a remote server?"
----------------------------
#7 09 Aug 2013 10:55
bluesxman
Something like this then?
Code: Select all
set "OutputFile=test.csv"
for /f "usebackq tokens=*" %%S in ("servers.txt") do (
for /F "skip=2 tokens=2-3 delims=," %%A in ('wmic computersystem get manufacturer^,model /FORMAT:csv /node:%%~S') do (
set "Manufacturer=%%A"
set "Model=%%B"
)
for /F "skip=2 tokens=2 delims=," %%A in ('wmic bios get serialnumber /FORMAT:csv /node:%%~S') do (
set "Serial=%%A"
)
call echo:%%~S, %%Manufacturer%%, %%Model%%, %%Serial%%>>"%OutputFile%"
)