Public/Get-PublicIP.ps1

function Get-PublicIP {

    <#
    .DESCRIPTION
    Returns WhoIS public IP info for your location or any specified public IP
 
    .Parameter IP
    Specify an IP to get WhoIs info for
 
    .EXAMPLE
    Returns local Public IP Info
 
    Get-PublicIP
 
    .Example
    Returns your Public IP Info
 
    Get-PublicIP -IP 8.8.8.8
 
    .Link
    Clear-DNSClientCache
    Get-DNSClientCache
    Get-NetIPConfiguration
    Get-NetworkStatistics
    Resolve-DNSName
    Test-Netconnection
    #>


    [CmdletBinding()]
    Param (
        [Parameter(Position = 0)]$IP
    )

    if ( $host.version.major -lt 6) {
        $ipinfo = Invoke-RestMethod http://ipinfo.io/$IP
        $PublicIP = @{
            IP       = $ipinfo.ip
            Hostname = $ipinfo.hostname
            City     = $ipinfo.city
            Region   = $ipinfo.region
            country  = $ipinfo.country
            loc      = $ipinfo.loc
            org      = $ipinfo.org
            Phone    = $ipinfo.phone
        }
        $PublicIP.getenumerator() | Sort-Object -property name
    }
    else {
        Write-Warning "The rest method used for this command is not compatible with PowerShell Core. So Invoke-Command is used against the localhost to return the same results. If the command Fails enable Powershell Remoting!"

        Invoke-Command -ComputerName $env:COMPUTERNAME -ScriptBlock {
            $ipinfo = Invoke-RestMethod http://ipinfo.io/$IP
            $PublicIP = @{
                IP       = $ipinfo.ip
                Hostname = $ipinfo.hostname
                City     = $ipinfo.city
                Region   = $ipinfo.region
                country  = $ipinfo.country
                loc      = $ipinfo.loc
                org      = $ipinfo.org
                Phone    = $ipinfo.phone
            }
            $PublicIP.getenumerator() | Sort-Object -property name
        }
    }
}