Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2209
  • Last Modified:

PSINFO - revision of script - Computername, filter - .csv

The below script works great except it outputs in the following format:

Computer A:
Microsoft Office

Computer B:
Microsoft Office

The problem is once imported as a .csv it dumps the info all into column "A".    Is there some way to get the output to be as such:

Computer A: , Microsoft Office
Computer B: , Microsoft Office

Thanks in advance.
@ECHO OFF

ECHO.

IF EXIST Temp RD /S /Q Temp

MD Temp

IF EXIST temp.txt DEL temp.txt

SET /P CLEAR_RESULTS=Clear Results.txt before starting new search? (y/n) 

IF NOT %CLEAR_RESULTS%==n IF EXIST Results.txt DEL /Q /F Results.txt

SET /P CLEAR_LOG=Clear Log.txt before starting new search? (y/n) 

IF NOT %CLEAR_LOG%==n IF EXIST Log.txt DEL /Q /F Log.txt

ECHO.

ECHO Please specify a software title to filter by (partial title names OK) or,
ECHO if none, please press the Enter key on your computer keyboard:

ECHO.

SET /P FILTER=

ECHO.

IF [%FILTER%]==[] GOTO UNFILTERED
IF NOT [%FILTER%]==[] GOTO FILTERED

PAUSE

EXIT

:UNFILTERED

CLS

ECHO.

ECHO Performing a software inventory on these machines
ECHO With no filter in place...

ECHO.

SETLOCAL 
SET key= 
FOR /F "Tokens=*" %%a IN ('type PCs.txt') DO SET line=%%a&call :PARSE 
ENDLOCAL
GOTO END 

:PARSE
::STRIP COMMAND CONTROL CODES 
SET work=%line:"=% 
SET work=%work::=% 
SET work=%work:(=% 
SET work=%work:)=% 
SET work=%work:^&=% 
SET work=%work:^|=% 
SET work=%work:^>=% 
SET work=%work:^<=% 
SET work=%work:^%=% 
SET work=%work:^!=% 
SET work=%work:^;=% 

::SAVE THE KEY
IF {%work:~0,1%}=={[} set key=%line%&goto :EOF
SET dw=%work:dword=% 
IF "%dw%" EQU "%work%" goto :EOF

SET filename=%line%
SET substring=%filename:~33,30% 
SET temp=%substring%
SET _string=%temp%
SET _endbit=%_string:*?=%
CALL SET _semiresult=%%_string:%_endbit%=%%
SET _result=%_semiresult:?=%

SET COMPUTERNAME=%line%

ECHO.

ECHO Checking to see if %COMPUTERNAME% is online...

PING -n 2 -w 500 %COMPUTERNAME% | FIND "Reply" > nul

IF %ERRORLEVEL%==0 GOTO STARTSCRIPT
IF %ERRORLEVEL%==1 GOTO NOREPLY

EXIT

:STARTSCRIPT

ECHO.

ECHO %COMPUTERNAME%:>>Results.txt

ECHO.>>Results.txt

FOR /F "TOKENS=* DELIMS= " %%b IN ('PSINFO \\%COMPUTERNAME% -s') DO ECHO %%b>>Results.txt

ECHO.>>Results.txt

EXIT /B

:FILTERED

CLS

ECHO.

ECHO Performing a software inventory on these machines
ECHO With the filter in place: %FILTER%

ECHO.

SETLOCAL 
SET key= 
FOR /F "Tokens=*" %%a IN ('type PCs.txt') DO SET line=%%a&call :PARSE 
ENDLOCAL
GOTO END 

:PARSE
::STRIP COMMAND CONTROL CODES 
SET work=%line:"=% 
SET work=%work::=% 
SET work=%work:(=% 
SET work=%work:)=% 
SET work=%work:^&=% 
SET work=%work:^|=% 
SET work=%work:^>=% 
SET work=%work:^<=% 
SET work=%work:^%=% 
SET work=%work:^!=% 
SET work=%work:^;=% 

::SAVE THE KEY
IF {%work:~0,1%}=={[} set key=%line%&goto :EOF
SET dw=%work:dword=% 
IF "%dw%" EQU "%work%" goto :EOF

SET filename=%line%
SET substring=%filename:~33,30% 
SET temp=%substring%
SET _string=%temp%
SET _endbit=%_string:*?=%
CALL SET _semiresult=%%_string:%_endbit%=%%
SET _result=%_semiresult:?=%

SET COMPUTERNAME=%line%

ECHO.

ECHO Checking to see if %COMPUTERNAME% is online...

PING -n 2 -w 500 %COMPUTERNAME% | FIND "Reply" > nul

IF %ERRORLEVEL%==0 GOTO STARTSCRIPT
IF %ERRORLEVEL%==1 GOTO NOREPLY

EXIT

:STARTSCRIPT

ECHO.

ECHO.>>Temp\%COMPUTERNAME%.txt
FOR /F "TOKENS=* DELIMS= " %%b IN ('PSINFO \\%COMPUTERNAME% -s') DO ECHO %%b>>Temp\%COMPUTERNAME%.txt

ECHO %COMPUTERNAME%:>>Results.txt

FOR /F "TOKENS=* DELIMS= " %%b IN ('FINDSTR /I "%FILTER%" Temp\%COMPUTERNAME%.txt') DO (

ECHO %%b>>Results.txt

)

ECHO.>>Results.txt

EXIT /B

:END

IF EXIST Temp RD /S /Q Temp

START Results.txt

EXIT

:NOREPLY

ECHO No Response From %COMPUTERNAME%>>Log.txt

Open in new window

0
beckman55
Asked:
beckman55
  • 3
  • 3
2 Solutions
 
vikas_madhusudanaCommented:
can you have something like this
FOR /F "TOKENS=* DELIMS= " %%b IN ('PSINFO \\%COMPUTERNAME% -s') DO ECHO %COMPUTERNAME%: %%b>>Results.txt

instead of

FOR /F "TOKENS=* DELIMS= " %%b IN ('PSINFO \\%COMPUTERNAME% -s') DO ECHO %%b>>Results.txt

0
 
Bill PrewCommented:
How about this?

~bp
@ECHO OFF
 
ECHO.
 
IF EXIST Temp RD /S /Q Temp
 
MD Temp
 
IF EXIST temp.txt DEL temp.txt
 
SET /P CLEAR_RESULTS=Clear Results.txt before starting new search? (y/n) 
 
IF NOT %CLEAR_RESULTS%==n IF EXIST Results.txt DEL /Q /F Results.txt
 
SET /P CLEAR_LOG=Clear Log.txt before starting new search? (y/n) 
 
IF NOT %CLEAR_LOG%==n IF EXIST Log.txt DEL /Q /F Log.txt
 
ECHO.
 
ECHO Please specify a software title to filter by (partial title names OK) or,
ECHO if none, please press the Enter key on your computer keyboard:
 
ECHO.
 
SET /P FILTER=
 
ECHO.
 
IF [%FILTER%]==[] GOTO UNFILTERED
IF NOT [%FILTER%]==[] GOTO FILTERED
 
PAUSE
 
EXIT
 
:UNFILTERED
 
CLS
 
ECHO.
 
ECHO Performing a software inventory on these machines
ECHO With no filter in place...
 
ECHO.
 
SETLOCAL 
SET key= 
FOR /F "Tokens=*" %%a IN ('type PCs.txt') DO SET line=%%a&call :PARSE 
ENDLOCAL
GOTO END 
 
:PARSE
::STRIP COMMAND CONTROL CODES 
SET work=%line:"=% 
SET work=%work::=% 
SET work=%work:(=% 
SET work=%work:)=% 
SET work=%work:^&=% 
SET work=%work:^|=% 
SET work=%work:^>=% 
SET work=%work:^<=% 
SET work=%work:^%=% 
SET work=%work:^!=% 
SET work=%work:^;=% 
 
::SAVE THE KEY
IF {%work:~0,1%}=={[} set key=%line%&goto :EOF
SET dw=%work:dword=% 
IF "%dw%" EQU "%work%" goto :EOF
 
SET filename=%line%
SET substring=%filename:~33,30% 
SET temp=%substring%
SET _string=%temp%
SET _endbit=%_string:*?=%
CALL SET _semiresult=%%_string:%_endbit%=%%
SET _result=%_semiresult:?=%
 
SET COMPUTERNAME=%line%
 
ECHO.
 
ECHO Checking to see if %COMPUTERNAME% is online...
 
PING -n 2 -w 500 %COMPUTERNAME% | FIND "Reply" > nul
 
IF %ERRORLEVEL%==0 GOTO STARTSCRIPT
IF %ERRORLEVEL%==1 GOTO NOREPLY
 
EXIT
 
:STARTSCRIPT
 
ECHO.
 
FOR /F "TOKENS=* DELIMS= " %%b IN ('PSINFO \\%COMPUTERNAME% -s') DO ECHO %COMPUTERNAME%,%%b>>Results.txt
 
ECHO.>>Results.txt
 
EXIT /B
 
:FILTERED
 
CLS
 
ECHO.
 
ECHO Performing a software inventory on these machines
ECHO With the filter in place: %FILTER%
 
ECHO.
 
SETLOCAL 
SET key= 
FOR /F "Tokens=*" %%a IN ('type PCs.txt') DO SET line=%%a&call :PARSE 
ENDLOCAL
GOTO END 
 
:PARSE
::STRIP COMMAND CONTROL CODES 
SET work=%line:"=% 
SET work=%work::=% 
SET work=%work:(=% 
SET work=%work:)=% 
SET work=%work:^&=% 
SET work=%work:^|=% 
SET work=%work:^>=% 
SET work=%work:^<=% 
SET work=%work:^%=% 
SET work=%work:^!=% 
SET work=%work:^;=% 
 
::SAVE THE KEY
IF {%work:~0,1%}=={[} set key=%line%&goto :EOF
SET dw=%work:dword=% 
IF "%dw%" EQU "%work%" goto :EOF
 
SET filename=%line%
SET substring=%filename:~33,30% 
SET temp=%substring%
SET _string=%temp%
SET _endbit=%_string:*?=%
CALL SET _semiresult=%%_string:%_endbit%=%%
SET _result=%_semiresult:?=%
 
SET COMPUTERNAME=%line%
 
ECHO.
 
ECHO Checking to see if %COMPUTERNAME% is online...
 
PING -n 2 -w 500 %COMPUTERNAME% | FIND "Reply" > nul
 
IF %ERRORLEVEL%==0 GOTO STARTSCRIPT
IF %ERRORLEVEL%==1 GOTO NOREPLY
 
EXIT
 
:STARTSCRIPT
 
ECHO.>>Temp\%COMPUTERNAME%.txt
FOR /F "TOKENS=* DELIMS= " %%b IN ('PSINFO \\%COMPUTERNAME% -s') DO ECHO %%b>>Temp\%COMPUTERNAME%.txt
 
FOR /F "TOKENS=* DELIMS= " %%b IN ('FINDSTR /I "%FILTER%" Temp\%COMPUTERNAME%.txt') DO (
 
ECHO %COMPUTERNAME%,%%b>>Results.txt
 
)
 
ECHO.>>Results.txt
 
EXIT /B
 
:END
 
IF EXIST Temp RD /S /Q Temp
 
START Results.txt
 
EXIT
 
:NOREPLY
 
ECHO No Response From %COMPUTERNAME%>>Log.txt

Open in new window

0
 
beckman55Author Commented:
Excellent!  The code works.   Respectfully...would it be easy to have the script create a "complete.txt" file once its completely done?

Thank you
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Bill PrewCommented:
Not sure I understand the question?  What would be in the complete.txt file?

~bp
0
 
beckman55Author Commented:
Nothing has to be in there.  Just once the script finishes running on all the pc's then it will create a complete.txt file.  This way the other admins will know if the script is done running and it's ok to pick up the "results" file from the server.

If there is a way to put the start time and end time of the script that would be cool.  But that's icing on the cake.
0
 
Bill PrewCommented:
Just add this near the top of your script:

IF EXIST complete.txt DEL complete.txt
SET StartStamp=%DATE% %TIME%

And then where ever you want to indicate it ended do this.

SET StopStamp=%DATE% %TIME%
ECHO Start: %StartStamp%>complete.txt
ECHO Ended: %StopStamp%>>complete.txt

~bp
0
 
beckman55Author Commented:
Thank you very much
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now