Disclaimer: i am not an expert at this. I put this script together based on combining multiple samples i saw from other scripts.
My goal is to use WMIC to output a CSV file of the current logged in user and all the software based on a list of PCs (PCLIST.txt) Here is what i have so far:
@echo off
FOR /f "tokens=1,2 delims= " %%a in (PCLIST.txt) do if exist "\\%%a\c$" (
WMIC /NODE: "%%a" COMPUTERSYSTEM GET USERNAME /format:csv >> ENVINV.csv
wmic /NODE: "%%a" Product get name, vendor /format:csv >> ENVINV.csv
) ELSE (
@ECHO %%a does not exist. Writing to text file.
@ECHO %%a >>ENVINV-error.txt
)
)
This is what i get as output:
Node,UserName
CCOMPUTER1,CCHNL\username
Node,Name,Vendor
CCOMPUTER1,Microsoft OneNote MUI (English) 2016,Microsoft Corporation
CCOMPUTER1,Microsoft Office OSM MUI (English) 2016,Microsoft
Corporation CCOMPUTER1,Microsoft Office Standard 2016,Microsoft
Corporation CCOMPUTER1,Microsoft Office OSM UX MUI (English)
2016,Microsoft Corporation CCOMPUTER1,Microsoft Office Shared Setup
Metadata MUI (English) 2016,Microsoft Corporation CCOMPUTER1,Microsoft
Excel MUI (English) 2016,Microsoft Corporation CCOMPUTER1,Microsoft
Office Shared 64-bit Setup Metadata MUI (English) 2016,Microsoft
Corporation CCOMPUTER1,Microsoft PowerPoint MUI (English)
2016,Microsoft Corporation CCOMPUTER1,Microsoft Publisher MUI
(English) 2016,Microsoft Corporation CCOMPUTER1,Microsoft Outlook MUI
(English) 2016,Microsoft Corporation
While workable, it would be much easier to sort and view if:
- there was no blank line at the top
- the First Line was simply just, "Node, Name, Vendor"
- the "Node" lines did not repeat for each time it cycled the for Loop
Thanks!