PowerShell or Batch file to report whether a file exists on remote computers -


i looking batch file or powershell script run on remote machines, check if file exists, , if doesn't, report .txt or .cvs file.

you can use test-path , add-content cmdlets achieve this. here's simple, generic example. can update reflect specific needs.

# step 1: build array of file paths $filelist = @(       '\\computer1\c$\path\to\file.txt'     , '\\computer2\share\file\name.ext'     , '\\computer3\path\to\foo\bar.txt'     )  # step 2: test each path , log text file foreach ($file in $filelist) {     if (!(test-path -path $file)) {         add-content -path 'c:\path\to\log file.log' -value "file not exist: $file";     } } 

to import list of computers, use get-content cmdlet:

# step 1: array of computer names , define path $computerlist = get-content -path c:\list\of\computers.txt; $filepath = '\\{0}\share\path\to\file.txt';  # step 2: test each path , log text file foreach ($computer in $computerlist) {     if (!(test-path -path ($filepath -f $computer))) {         add-content -path 'c:\path\to\log file.log' -value "file not exist: $file";     } } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -