Script is looping without an end

Need help with this script. I am trying to get the os, version and patches installed on a server. When i run the script the loop is not stopping and it seems to be running forever until i intervene and stop the script. Please help me in understanding where i am going wrong.

@echo off
setlocal

rem Define output file location
set outputfile=%computername%.csv

rem Overwrite output file and add header line
echo Caption,Version,Node,Description,Type,HotFixID,InstalledBy,InstalledOn>>%outputfile%

rem Gather all data desired
for /f "skip=2 tokens=2 delims=," %%a in ('wmic os get caption /format:csv') do (
  for /f "skip=2 tokens=2 delims=," %%b in ('wmic os get version /format:csv') do (
    for /f "skip=2 tokens=2 delims=," %%c in ('wmic qfe get csname /format:csv') do (
      for /f "skip=2 tokens=2 delims=," %%d in ('wmic qfe get caption /format:csv') do (
        for /f "skip=2 tokens=2 delims=," %%e in ('wmic qfe get description /format:csv') do (
          for /f "skip=2 tokens=2 delims=," %%f in ('wmic qfe get hotfixid /format:csv') do (
            for /f "skip=2 tokens=2 delims=," %%g in ('wmic qfe get installedby /format:csv') do (
              for /f "skip=2 tokens=2 delims=," %%h in ('wmic qfe get installedon /format:csv') do (
              rem Write merged results to output file
                  echo "%%~a","%%~b","%%~c","%%~d","%%~e","%%~f","%%~g","%%~h">>%outputfile%
            )
          )
        )
      )
    )
   )
 )
)
Raj ShivaramSenior ArchitectAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
Give this a try, should work better...

You want to gather all the fields you want from each class on a single WMIC execution, not do a separate WMIC for each field.  So you only needed two WMIC executions.

Also, when doing CSV output, the Node will always be added as the first column, and then the rest of the columns will appear in sorted name order.  So you need to account for that, I always place them on the WMIC execution in that order just to keep it straight.

Also, WMIC adds a trailing carriage return that often messes up usage of the last column, so if possible I add the last available column to the list even though I don't want that value.  It resolves the format of the rest of the fields.  

@echo off
setlocal

rem Define output file location
set outputfile=%computername%.csv

rem Overwrite output file and add header line
echo Caption,Version,Node,Description,Type,HotFixID,InstalledBy,InstalledOn>>%outputfile%

rem Gather all data desired
for /f "skip=2 tokens=2-3 delims=," %%a in ('wmic os get caption^,version^,WindowsDirectory /format:csv') do (
  for /f "skip=2 tokens=2-7 delims=," %%c in ('wmic qfe get caption^,csname^,description^,hotfixid^,installedby^,installedon^,status /format:csv') do (
    rem Write merged results to output file
    echo "%%~a","%%~b","%%~d","%%~c","%%~e","%%~f","%%~g","%%~h">>%outputfile%
  )
)

Open in new window


»bp
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Raj ShivaramSenior ArchitectAuthor Commented:
Thank you so much Bill for helping me fix the looping issue and also correcting the script. Also thanks for the tip for adding additional column, I will use it in future.
0
Bill PrewIT / Software Engineering ConsultantCommented:
Welcome, glad that was helpful.


»bp
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.