Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
PowerShell function to get the geolocation for one or more IP Addresses
function Get-MvaIpLocation {
Retrieves Geo IP location data
This command retrieves the Geo IP Location data for one or more IP addresses
.PARAMETER IPAddress <String[]>
Specifies one or more IP Addresses for which you want to retrieve data for.
Get-MvaIpLocation -ipaddress '',''
'','' | Get-MvaIpLocation
Author: Mario van Antwerpen
Param (
[Parameter(ValueFromPipeline, Mandatory, Position = 0, HelpMessage = "Enter an IP Address")]
if ($_ -match '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$') {
} else {
Throw "$_ is not a valid IPv4 Address!"
begin {
Write-Verbose -message "Starting $($MyInvocation.Mycommand)"
process {
foreach ($entry in $ipaddress) {
$restUrl = "$entry"
try {
Write-Verbose -Message "Connecting to rest endpoint"
$result = Invoke-RestMethod -Method get -Uri $restUrl
Write-output $result
catch {
Write-Verbose -Message "Catched and error"
end {
Write-Verbose -message "Ending $($MyInvocation.Mycommand)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment