Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Tips on my url checking script

$
0
0

Ive inherited a list of 3500 urls that i need to check for validity. I wrote a script that is working but takes literally 12 hours to finish. It pulls the urls from column a of an excel spreadsheet and then records the results in column b, after it finishes the list it then starts at the top again but assigns a different preface to the url and puts the output in column c, after it checks the urls for web requests it then pings all the urls with and without www. After its checked the list 6 times it then saves it the spreadsheet. I was wondering if there is anyway to speed this up?

 

#this calls excel and supresses dialogues

$Excel = New-Object -ComObject Excel.Application

$Excel.Visible = $False

$Excel.DisplayAlerts = $False

#opens the excel file

$wb = $Excel.Workbooks.Open("$env:userprofile\documents\urlchecklist.xlsx")

#switches to the url sheet

$ws = $Excel.Worksheets.item("Urls")

#gets range info from user and puts it into a variable

[int]$startrow = Read-Host "What is the starting row?"

[int]$stoprow = Read-Host "What is the row to stop on?"

#intake row and column variables

$inrow = $startrow

$incolumn = 1

#write out row and column variables

$outrow = $inrow

$outcolumn = 2

 

#loop with the http://www.

do

{

try

{

$HTTP_Status = $null

#sets the url variable to cell

$urlin = $ws.Cells.Item($inrow,$incolumn).Text

$httppreface = "http://www."

$urltocheck = $httppreface + $urlin

Write-Output "$urltocheck"

# First we create the request.

$HTTP_Request = [System.Net.WebRequest]::Create($urltocheck)

$HTTP_Request.Method="HEAD"

$HTTP_Request.Timeout = 15000

# We then get a response from the site.

$HTTP_Response = $HTTP_Request.GetResponse()

# We then get the HTTP status.

$HTTP_Status = $HTTP_Response.StatusCode

Write-Output "$HTTP_Status"

$ws.cells.Item($outrow,$outcolumn).Value2 = "Site is OK!"

}

catch

{

Write-Output "Offline"

$ws.cells.Item($outrow,$outcolumn).Value2 = "Offline"

}

# Finally, we clean up the http request by closing it.

$HTTP_Response.Close()

#ends the checking loop

$inrow++

$outrow++

}

until($inrow -gt $stoprow) 

#itterates the out column,resets other variables then starts loop with the new preface

$outcolumn++

$inrow = $startrow

$outrow = $inrow

 

i simple pasted this loop multiple times with different prefaces for the url: http://,http://www,https:// and https://www.


Viewing all articles
Browse latest Browse all 6937

Trending Articles