Inspired by this RidiCurious post, I decided to add to his initial script and give it my own little twist. This will show you how to get Alexa ranking using Powershell.
In order to keep things nice and uniform I wanted to remove the http(s)://
from the beginning of the link url. I also wanted to remove any trailing slashes to give it the added visual effect. To do that I used some regex wizardry and slapped that into a function. The function, by default, allows for domain names to be passed through the pipeline and goes through each domain one by one and outputs into a nice table. Let’s take a look at the script below.
Get Alexa Ranking Using Powershell
Function Get-AlexaRank { <# .Synopsis This script will get the current Alexa rank. Inspired by: https://ridicurious.com/2018/09/21/how-to-check-alexa-ranking-using-powershell/ For updated help and examples refer to -Online version. .DESCRIPTION Search for a single site or enter in multiple sites. For updated help and examples refer to -Online version. .NOTES Name: Get-AlexaRank Author: The Sysadmin Channel Version: 1.0 DateCreated: 2019-Jan-09 DateUpdated: 2019-Jan-09 .LINK https://thesysadminchannel.com/get-alexa-ranking-powershell - .EXAMPLE For updated help and examples refer to -Online version. #> [CmdletBinding()] param( [Parameter( ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [string[]] $DomainList = 'https://thesysadminchannel.com/' ) BEGIN {} PROCESS { foreach ($Domain in $DomainList) { try { #Removing leading http(s) and trailing forward slash if it's added. $Domain = $Domain -Replace ('htt.+://') $Domain = $Domain -Replace ('/.+|/') $Data = (Invoke-RestMethod "http://data.alexa.com/data?cli=10&dat=s&url=$Domain").alexa.sd[1] $USRank = $Data.Country | Where-Object {$_.Code -eq 'US'} | select -ExpandProperty Rank $Properties = @{Domain = $Domain GlobalRank = '{0:N0}' -f ([int]$Data.Popularity.Text) USRank = '{0:N0}' -f ([int]$USRank) GlobalDelta = '{0:N0}' -f ([int]$Data.Rank.Delta) } $Object = New-Object -TypeName PSCustomObject -Property $Properties | Select Domain, GlobalRank, USRank, GlobalDelta } catch { $ErrorMessage = $Domain + " Error: " + $_.Exception.Message } finally { Write-Output $Object $Object = $null $Data = $null $Domain = $null } } } END {} }
Given the 2 screenshots it’s easy to read the alexa rank. One thing to note is that a negative delta is a good thing. It means that your site is growing in traffic and the closer you are to 1, the better. In my case I went more than 1.2 million spots in in rank over the past 3 months (GlobalDelta). While search engine giants, Google and Youtube secured their spots as number 1 and number 2 most visited sites in the world.
Speaking of Youtube, don’t forget to check out our very own Youtube Channel for awesome sysadmin content. That’s only if you’re into that kind of stuff.