• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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