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