INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

output url status html

output url status html

(OP)
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 --> powershell

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

$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" 

RE: output url status html

(OP)
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).

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close