Help needed in printing the text
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.
@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,
September 7th, 2015 7:05am

Put code in file and run.

Use output statements to output steps in loop.

To learn how to use PowerShell go here: https://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx?f=255&MSPPError=-2147217396

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 7:29am

Just for example -

"http://Www.google.com" , "http://www.bing.com"  , "http://" , "http://www.bing.com"| %{
try
    {
        "Checking..." + $_ + " and the result is " + [int][System.Net.WebRequest]::Create($_).GetResponse().StatusCode
    }
Catch
    {
        $_.Exception
    }
}



September 7th, 2015 7:47am

Hi Jrv,

I learned basics. I tried with write -host and it worked. I am newbie to this technology. The code which i posted  taking long time to respond. it's taking  minute to check 5 url's which is very slow. I have 25mbps internet speed.

Is there any way to improve the speed of this process

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 8:41am

You need to learn the basics and not just say you don't know.  Thecode youposted shows you have no idea about PowerShell and it will not work.

Put this in a file and run it.

get-Content links.txt|
    ForEach-Object{
          try{
              $wr=[Net.WebRequest]::Create($_)
              if($wr.GetResponse().Statuscode -eq 200){
                  Write-Host $_ -fore green
} } Catch{ "$_" } }
September 7th, 2015 8:54am

Fixed the typo in the code missing closing } in if statement

get-Content links.txt|
    ForEach-Object{
          try{
              $wr=[Net.WebRequest]::Create($_)
              if($wr.GetResponse().Statuscode -eq 200){
                  Write-Host $_ -fore green }
           }
           Catch{
              "$_"
           }
     }

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 9:14am

Thanks jrv and honestly i tried with  your approch before posting in this thread. reading the records from text file and looping through with foreach. Even i tried with multiple approach. but the process is slow. Not sure why.

sample test url

http://www.google.com
https://www.google.com
http://www.teeeelstra.com
https://www.teeeelstra.com
http://www.telstra.com
https://www.telstra.com
http://www.teeeelstra.com/images/smilies/icon_rollrrreyes.gif
http://www.teeeelstra.com/images/smilies/icon_rolleyes.gif

Even your code also little slow. it's taking 15 to 20 seconds to check 6 url. I tried with wget and it's faster then powershell. I thought powershell will be much faster. But it's not. Is my thought is correct?

Thanks

September 7th, 2015 9:21am

://www.teeeelstra.com/images/smilies/icon_rolleyes.gif

Even your code also little slow. it's taking 15 to 20 seconds to check 6 url. I tried with wget and it's faster then powershell. I thought powershell will be much faster. But it's not. Is my thought is correct?

That has nothing to do with the script. It takes time to access a web page. It is you network.

Your webpages are also slow in respo

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 9:22am

I ran my code and it took less than 3 seconds.

http://www.google.com
https://www.google.com
Exception calling "GetResponse" with "0" argument(s): "The remote name could not be resolved: 'www.teeeelstra.com'"
Exception calling "GetResponse" with "0" argument(s): "The remote name could not be resolved: 'www.teeeelstra.com'"
http://www.telstra.com
https://www.telstra.com
Exception calling "GetResponse" with "0" argument(s): "The remote name could not be resolved: 'www.teeeelstra.com'"
Exception calling "GetResponse" with "0" argument(s): "The remote name could not be resolved: 'www.teeeelstra.com'"
PS C:\scripts>

September 7th, 2015 9:27am

thanks , i will do more research. Appreciated your precious time on this post
Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 9:34am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics