Help needed in printing the text

born2achieve

New member
Local time
5:34 PM
Messages
36
Hello Friends,

I am having bunch of url and trying to check whihc url has broken. Finlly endup with creating powershell command. below the code working fine.
Code:
@echo off
powershell -command "gc 'links.txt'|%%{if($(try{[int][Net.WebRequest]::Create($_).GetResponse().Statuscode}Catch{}) -eq 200){$_}}|sc 'True_URL.txt'"
pause

But, Is there any way to print the running url? Right now i don't see what's happening on the screen. it's blank. But the process is running. I would like see which url is getting checked. Any suggestion please,
thanks
 

My Computer

Computer type
PC/Desktop
OS
windows7 64 bit
Hi there,

This should do,
Code:
@powershell "gc 'links.txt'|%%{'Processing: '+$_;if($(try{[int][Net.WebRequest]::Create($_).GetResponse().Statuscode}Catch{}) -eq 200){$_|ac 'True_URL.txt'}}"
pause
 
Last edited:

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Hi PYP,

Thanks and it worked. But this process is dead slow and is there any better way to achieve this functionality. i have 100*1000 url's in text file.

Thanks
 

My Computer

Computer type
PC/Desktop
OS
windows7 64 bit
I thought it was a little sluggish. The line you gave me fails to release the object returned by the GetResponse method. Bad memory leaks.

Try this,
Code:
@powershell "gc 'links.txt'|%{'Processing: '+$_;try{$r=[Net.WebRequest]::Create($_).GetResponse();if([int]$r.StatusCode -eq 200){$_|ac 'True_URL.txt'}}Catch{}finally{$r.Close()}}"
 
Last edited:

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Thanks and getting error message when i run
The string starting:
At line:1 char:119
+ gc 'links.txt'| '+$_;try{$r=[Net.WebRequest]::Create($_).GetResponse();if([int]$r.StatusCode -eq 200){$_|ac 'True_URL.txt <<<< '}}Catch{}finally{$r.Close()}}
is missing the terminator: '.
At line:1 char:149
+ gc 'mm.txt'| '+$_;try{$r=[Net.WebRequest]::Create($_).GetResponse();if([int]$r.StatusCode -eq 200){$_|ac 'True_URL.txt'}}Catch{}finally{$r.Close()}} <<<<
+ CategoryInfo : ParserError: (}}Catch{}finally{$r.Close()}}:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

any suggestion please
 

My Computer

Computer type
PC/Desktop
OS
windows7 64 bit
Sorry, it's probably the fancy formatting I've used that was interfering with your copy-paste. I've removed the colours now.
 

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Sorry Dude, Still getting the error. am also analysis whats wrong.

Code:
@echo off
@powershell "gc 'links.txt'|%{'Processing: '+$_;try{$r=[Net.WebRequest]::Create($_).GetResponse();if([int]$r.StatusCode -eq 200){$_|ac 'True_URL.txt'}}Catch{}finally{$r.Close()}}"
pause

output:
The string starting:
At line:1 char:119
+ gc 'mm.txt'| '+$_;try{$r=[Net.WebRequest]::Create($_).GetResponse();if([int]$r.StatusCode -eq 200){$_|ac 'True_URL.txt <<<< '}}Catch{}finally{$r.Close()}}
is missing the terminator: '.
At line:1 char:149
+ gc 'mm.txt'| '+$_;try{$r=[Net.WebRequest]::Create($_).GetResponse();if([int]$r.StatusCode -eq 200){$_|ac 'True_URL.txt'}}Catch{}finally{$r.Close()}} <<<<
+ CategoryInfo : ParserError: (}}Catch{}finally{$r.Close()}}:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

Press any key to continue . . .
 

My Computer

Computer type
PC/Desktop
OS
windows7 64 bit
Hm. The command line in the error message does not seem to match up with your code. Please retry that batch file.
 

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Back
Top