#
👀 Search-IsItUp Powershell Module
Yeah okay so it may have not been that big a gap, but still might stop people asking if a website is up or down.
#
Powershell Function 👓
Okay so the story behind this epic quest, was I was flicking through twitter, and saw someone asking if this particular website was working. Not that this is enough to make me jump out my chair flip on my cape and costume and fly off to save the day. But it did get me thinking if there was a module out there to check if a website is up or down. I did not find one, so that sparked 💡 an idea to look for something which would do this.
I stumbled across this site above when looking for how to achieve this, and although I am not using an API to get this data, it involves a slightly different approach. As always in life there is more than one way to do something, it might not be the best way, but if it works, and is done in a quick time, then that is enough for me to go with that method.
So I found that by manually using this site, it changes the URL based on the website name you provide it. So in the below link I wanted to see if news.bbc.co.uk was up or down
I noticed that the URL had changed to the website I had provided, so I could use the term URL Hacking to provide the website name as a parameter and feed it to this URL isitup.org/param which would then produce the brief text that is displayed on the webpage after the check is complete
news.bbc.co.uk is up 🎉
It took 0.101 seconds to get a 200 status code from an IP address of 151.101.112.81.
#
Figured Use Invoke-WebRequest 🎯
So I decided this was a good enough webpage to use to get this information so the next time someone is asking is this website up or down? I can point them to use this module which will then tell them the answer, and they then do not have to ask the whole world a question they can now answer themself. Yeah I know in reality that this will probably not happened, but I was now commited enough to try and solve some big-time first world problems with this idea 💡
So firstly I used the Invoke-WebRequest to connect to the site, and pass the website name I am interested in as a paramerter and get back the results. Now I know this is not the most complicated function out there, as it is only a few lines long. However, it will show those out there that do not know how to scrape webpages for data a nifty little trick.
As mentioned the data returned from the website is minimal, but the webpage itself is made up of HTML and I need to filter through that HTML to get just the bits of text I needed.
#
Search-IsItUp Code 🔎
<#
.Synopsis
Checks to wee if a website is up
.DESCRIPTION
Uses the website https://isitup.org to check if the specified website is up or down, and reports the results back
.EXAMPLE
Search-IsItUp -DomainName powershellgallery.com
Yay, powershellgallery.com is up.
It took 0.463 seconds to get a 200 status code from an IP address of 40.87.85.101.
.EXAMPLE
"dailymail.co.uk","thesun.co.uk","news.bbc.co.uk" | Search-IsItUp
Yay, dailymail.co.uk is up.
It took 0.041 seconds to get a 200 status code from an IP address of 184.30.21.195.
Yay, thesun.co.uk is up.
It took 0.182 seconds to get a 200 status code from an IP address of 18.66.122.18.
Yay, news.bbc.co.uk is up.
It took 0.089 seconds to get a 200 status code from an IP address of 151.101.112.81.
#>
function Search-IsItUp {
[CmdletBinding()]
Param
(
# Domain name like powershellgallery.com
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
Position = 0)]
$DomainName
)
Begin {
}
Process {
foreach ($Domain in $DomainName) {
try {
$data = Invoke-WebRequest -Uri https://isitup.org/$Domain
($data.ToString() -split "[`r`n]" | Select-String $Domain | Select-Object -First 1) -replace "<title>", "" -replace "</title>", ""
($data.ToString() -split "[`r`n]" | Select-String "it took" | Select-Object -First 1) -replace '<p class="smaller">', "" -replace "</p>", ""
}
catch {
$bad = $_
Write-Warning "Something went wrong:- $bad"
}
}
}
End {
}
}
As you see I have included a decent help file for this module, which also includes a few examples. I thought about the DomainName parameter, and the fact that people might want to check multiple websites at the sametime, so I allowed this parameter to accept pipeline input to make this happen. You also can see how I extracted the data I wanted from the HTML off of the website, and display this onto your console screen. I just hate leaving the console to do tasks, so this made that happen.
#
Thank you 👋
Hopefully this module will make you think about what you can do with the data returned from any website and how you could scrape that data automatically. As always I like to try and keep things interesting, and to try and make something unique and useful as the end module product. The Powershell Gallery now has a module to see if any website or websites are up or down. Without even leaving the shell to obtain this information