M
Matt Williamson
I'm working on a script to get File version info for files on remote
systems. They way I'm doing it is by creating a script that determines
what fixed drives exist and running it remotely using psexec and parsing
the return info. I'm then taking the returned drives and doing a dir /s
on the remote unc path starting with the root drive so it returns all
files on that machine on all fixed drives that match. Then, I'm parsing
the output from the DIR looking for "Directory of" to get that path and
running Filever.exe on the file found at the path. So far, I have the
following script
[1]@echo off
[2]setlocal ENABLEDELAYEDEXPANSION
[3]
[4]cd /d %~dp0
[5]
[6]:: Input 1 PC or get list of ALL in domain
[7]IF "%1"=="" (
[8] set arg='NET VIEW ^^^| FIND "\\"'
[9]) ELSE (
[10] set arg="\\%1"
[11])
[12]
[13]set yfn=OrionMgr.exe
[14]
[15]For /F %%a in (%arg%) do (
[16] set pcname=%%a
[17] ping -n 1 !pcname:\\=! |find "TTL=" >nul
[18] if errorlevel 1 echo.!pcname! is offline
[19] if not errorlevel 1 (
[20] echo.!pcname!
[21] :: get drive letters of fixed drives
[22] for /f "skip=4" %%b in ('psexec !pcname! -cf Drivetype.cmd') do (
[23] set drv=%%b
[24] if "!drv:~1,1!"==" " set drv=!drv:~0,1!
[25] set yfp=!pcname!\!drv!$\%yfn%
[26] for /f "tokens=3*" %%c in ('dir /s !yfp!^|find "Directory of"')
do (set path1=%%c %%d)
[27] set path1=!path1!\%yfn%
[28] if exist "!path1!" (
[29] for /f "Tokens=2*" %%f in ('filever /v "!path1!"^>nul
2^>^&1^|find "ProductVersion"') do (echo !path1! - %%f%%g)
[30] set path1=
[31] )
[32] )
[33] )
[34])
This is the DriveType.cmd Script
[1]@echo off
[2]setlocal ENABLEDELAYEDEXPANSION
[3]for /f "tokens=1,2" %%a in ('fsutil fsinfo drives^|more') do (
[4] for /f "tokens=1" %%c in ('echo/%%b %%a') do (
[5] for /f "tokens=3" %%d in ('fsutil fsinfo drivetype %%c') do (
[6] if "%%d"=="Fixed" (
[7] set drv=%%c&set drv=!drv:~0,1!&echo.!drv!)
[8] )
[9] )
[10])
Right now when I run the main script, It's returning the path to the
file and version number, but it's also giving me "File or Network Path
not found" as well. I think it's because when I parse the return for
Drivetype from PsExec, it's getting extra junk. I can't figure out what
command that error is comming from so I can suppress it. Any insight on
this matter would be greatly appreciated.
systems. They way I'm doing it is by creating a script that determines
what fixed drives exist and running it remotely using psexec and parsing
the return info. I'm then taking the returned drives and doing a dir /s
on the remote unc path starting with the root drive so it returns all
files on that machine on all fixed drives that match. Then, I'm parsing
the output from the DIR looking for "Directory of" to get that path and
running Filever.exe on the file found at the path. So far, I have the
following script
[1]@echo off
[2]setlocal ENABLEDELAYEDEXPANSION
[3]
[4]cd /d %~dp0
[5]
[6]:: Input 1 PC or get list of ALL in domain
[7]IF "%1"=="" (
[8] set arg='NET VIEW ^^^| FIND "\\"'
[9]) ELSE (
[10] set arg="\\%1"
[11])
[12]
[13]set yfn=OrionMgr.exe
[14]
[15]For /F %%a in (%arg%) do (
[16] set pcname=%%a
[17] ping -n 1 !pcname:\\=! |find "TTL=" >nul
[18] if errorlevel 1 echo.!pcname! is offline
[19] if not errorlevel 1 (
[20] echo.!pcname!
[21] :: get drive letters of fixed drives
[22] for /f "skip=4" %%b in ('psexec !pcname! -cf Drivetype.cmd') do (
[23] set drv=%%b
[24] if "!drv:~1,1!"==" " set drv=!drv:~0,1!
[25] set yfp=!pcname!\!drv!$\%yfn%
[26] for /f "tokens=3*" %%c in ('dir /s !yfp!^|find "Directory of"')
do (set path1=%%c %%d)
[27] set path1=!path1!\%yfn%
[28] if exist "!path1!" (
[29] for /f "Tokens=2*" %%f in ('filever /v "!path1!"^>nul
2^>^&1^|find "ProductVersion"') do (echo !path1! - %%f%%g)
[30] set path1=
[31] )
[32] )
[33] )
[34])
This is the DriveType.cmd Script
[1]@echo off
[2]setlocal ENABLEDELAYEDEXPANSION
[3]for /f "tokens=1,2" %%a in ('fsutil fsinfo drives^|more') do (
[4] for /f "tokens=1" %%c in ('echo/%%b %%a') do (
[5] for /f "tokens=3" %%d in ('fsutil fsinfo drivetype %%c') do (
[6] if "%%d"=="Fixed" (
[7] set drv=%%c&set drv=!drv:~0,1!&echo.!drv!)
[8] )
[9] )
[10])
Right now when I run the main script, It's returning the path to the
file and version number, but it's also giving me "File or Network Path
not found" as well. I think it's because when I parse the return for
Drivetype from PsExec, it's getting extra junk. I can't figure out what
command that error is comming from so I can suppress it. Any insight on
this matter would be greatly appreciated.