Friday, August 30, 2019

Using powershell to check company information

I had a long list of companynames but no homepage adress.
Using the swedish yellow pages service Eniro I could use powershell to get the information.
This script only gets the first result with homepage attribut added, but depending on what you put the results may vary.

function ping-company {
param(
$profile = "<profileName>",
$key = "<apiKey>",
$version = "1.1.3",
$searchWord
)
$url = "https://api.eniro.com/cs/search/basic?profile=$($profile)&key=$($key)&country=se&version=$($version)&search_word=$($searchWord)"
$result = Invoke-RestMethod -Uri $url
$queryResult = $result.adverts |where-object {![string]::IsNullOrEmpty($_.homepage)} |select -first 1
$request = Invoke-WebRequest -Uri $queryResult.homepage
$homepage = (($($request.ParsedHtml.getElementsByTagName("meta")|select -ExpandProperty content)).split(";")|where-object {$_ -like "url=*"}).replace("url=","")
return $homepage
}
$searchWord = "Lantmännen"
$searchWord = [System.Web.HttpUtility]::UrlEncode($searchWord)
ping-company -searchWord $searchWord


Powershell and Uptimerobot

Uptimerobot can be quite tedious when you need to update many monitors at once. For example say you bought the license for Uptimerobot and n...