Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

output url status html

Status
Not open for further replies.

craigey

Technical User
Apr 18, 2002
510
0
0
GB
Hi,

The script below is successfully checking a list of wsdls & was outputting to the console the correct status. However I've tried converting the output to HTML, but the output from the $body variable is blank (I'm guessing this is because it's not an object), but I don't know how to make it one.

Ideally I'd like the script to output the wsdl url, ($_) and the status (either HTTP_Status or text 'Site Is OK'). If I can get that at least into the TEMP.html output file then I think I can use a replace to set the appropriate colour of the table cell.

Code:
$URLList = Get-Content -path C:\wsdls.txt
# First create the request.
# $HTTP_Request = [System.Net.WebRequest]::Create('[URL unfurl="true"]http://somefakeurlthatImadeup.com')[/URL]
# $HTTP_Request = [System.Net.WebRequest]::Create('[URL unfurl="true"]http://google.com')[/URL]

$body = $URLList | foreach {$HTTP_Request = [System.Net.WebRequest]::Create($_)
$notfound = 0
# We then get a response from the site.
try{
$HTTP_Response = $HTTP_Request.GetResponse()
}
catch {
    $ErrorMessage = $_.Exception.Message
    $FailedItem = $_.Exception.ItemName
    #Write-Host $ErrorMessage +$FailedItem
    If ($ErrorMessage = 'Exception calling "GetResponse" with "0" argument(s):'){
#    Write-Host "URL Not Found"
    $notfound = 1
    }
 #   throw $ErrorMessage +$FailedItem
}
# We then get the HTTP code as an integer.
If ($notfound -eq 0) {
$HTTP_Status = [int]$HTTP_Response.StatusCode

If ($HTTP_Status -eq 200) { 
    Write-Host "Site is OK!"
}
Else {
    Write-Host "Not OK"
}

}
# Finally, we clean up the http request by closing it.
$HTTP_Response.Close()

} 
Write-Host ($body | Format-Table | Out-String)

#$colorTagTable = @{OK = ' bgcolor="#00ff00">Site OK<';
#                   NotOK = ' bgcolor="#ff0000">Not OK<'}

#get possible values look them in text surrounded by > < and replace them
#$colorTagTable.Keys | foreach { $body = $body -replace ">$_<",($colorTagTable.$_) }

ConvertTo-HTML -body "<H2>WSDL Status</H2> $body" | Out-File "C:\TEMP.htm"
 
Never mind. I found an alternate script that I managed to merge with this one to do what I needed to do. I had to use the System.Net.WebRequest method as the invoke-webrequest was producing a HTTP status of 0 despite the sites being accessible (it worked fine on my local machine, but had issues on my remote servers).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top