• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 150
  • Last Modified:

Need to search all machines in the file if any files exist in the location

Hi,

I want a script that can scan all machine names in the txt file and get the file names if any available in this path.

C:\WINDOWS\System32\GroupPolicy\User\Scripts\Logon

Regards
Sharath
0
bsharath
Asked:
bsharath
  • 2
1 Solution
 
SteveGTRCommented:
You could try this:

@echo off

setlocal

set inFile=%~1

if "%~1"=="" set /p inFile=Please enter the maachine list file:
if "%inFile%"=="" echo Processing aborted&goto :EOF

if not exist "%inFile%" echo %inFile% does not exist&goto :EOF

for /f "tokens=*" %%a in ('type "%inFile%"') do (
  echo Machine: %%a
  dir /b "\\%%a\c$\WINDOWS\System32\GroupPolicy\User\Scripts\Logon"
)
0
 
bsharathAuthor Commented:
Hi Steve,

Can i get the results to a file...
0
 
SteveGTRCommented:
Sure:

@echo off

setlocal

set inFile=%~1

if "%~1"=="" set /p inFile=Please enter the maachine list file:
if "%inFile%"=="" echo Processing aborted&goto :EOF

if not exist "%inFile%" echo %inFile% does not exist&goto :EOF

set outFile=%~n0.txt

if exist "%outFile%" del "%outFile%" >NUL

for /f "tokens=*" %%a in ('type "%inFile%"') do (
  echo Machine: %%a >>"%outFile%"
  dir /b "\\%%a\c$\WINDOWS\System32\GroupPolicy\User\Scripts\Logon">>"%outFile%"
)

if not exist "%outFile%" echo Nothing processed&goto :EOF

echo Output in %outFile%
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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