list non-accessible Remote computers via a Script

jskfan
jskfan used Ask the Experts™
on
list non-accessible Remote computers via a Script

I have a script below that add printer and it  works just fine when I run it against accessible computers that are listed on the file "CompPrinterConf.txt"

I would like to have the script generate another file that displays computers that the script could not access.

usually if try \\remotecomputer\c$  and am able to access the remote computer then the script will run successful , otherwise it fails.
However when you have so many remote computers then it would be better to have a script that generates non accessible computers in a separate file.


Thank you

@echo off
setlocal
for /f %%a in (CompPrinterConf.txt) do (
	@echo starting pnpport on %%a
	cscript.exe "C:\windows\system32\Printing_Admin_Scripts\en-US\prnport.vbs" -a  -s %%a -r "PortName" -h hostname -o raw -n 9100
	@echo Waiting 5 seconds
	timeout 5
	@echo starting setting MyPrinter on %%a
	cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -a  -p "Myprinter" -m "Generic / text only" -r "PortName" -s %%a
	REM Not really needed, because the script will continue with the next machine
	REM timeout 5
)

@echo starting powershell
PowerShell.exe -ExecutionPolicy Bypass -Command  c:\Scripts\printer.ps1
REM timeout 5

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
NVITEnd-user support

Commented:
@echo off
setlocal enabledelayedexpansion
set fnLogFail=%temp%\pingfail.txt

for /f %%a in (CompPrinterConf.txt) do (
  ping -n 1 "%%a" | findstr /r /c:"[0-9] *ms"

  if !errorlevel! == 0 (
    @echo starting pnpport on %%a
    cscript.exe "C:\windows\system32\Printing_Admin_Scripts\en-US\prnport.vbs" -a  -s %%a -r "PortName" -h hostname -o raw -n 9100
    @echo Waiting 5 seconds
    timeout 5
    @echo starting setting MyPrinter on %%a
    cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -a  -p "Myprinter" -m "Generic / text only" -r "PortName" -s %%a
    REM Not really needed, because the script will continue with the next machine
    REM timeout 5
    @echo starting powershell
    PowerShell.exe -ExecutionPolicy Bypass -Command  c:\Scripts\printer.ps1
    timeout 5
  ) else (
      echo %date% %time% %0 can't connect to %%a>> %fnLogFail%
  )
)

Open in new window

Author

Commented:
I have shutdown one computer in purpose and ran the script but It is not doing anything
End-user support
Commented:
Reposted corrected code
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Author

Commented:
where is the corrected code ?
NVITEnd-user support

Commented:
Original post corrected

Author

Commented:
I will test this later ..
Thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial