PublicIP.psm1

[CmdletBinding()]
param()

if ($PSVersionTable.PSVersion -lt '6.0') {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute(
        'PSAvoidAssignmentToAutomaticVariable', '', Justification = 'Compatibility with PowerShell 6.0 and newer.'
    )]
    $IsWindows = [System.Environment]::OSVersion.Platform -eq 'Win32NT'
}

$scriptName = 'PublicIP'
Write-Verbose "[$scriptName] - Importing module"

#region - From [public]
Write-Verbose "[$scriptName] - [public] - Processing folder"

#region - From [public] - [Get-PublicIP]
Write-Verbose "[$scriptName] - [public] - [Get-PublicIP] - Importing"

function Get-PublicIP {
    <#
        .SYNOPSIS
        Gets your public IP address.

        .DESCRIPTION
        Gets your public IP address. You can specify a provider to use by using the Provider parameter.

        .EXAMPLE
        Get-PublicIP

        .EXAMPLE
        Get-PublicIP -Provider MyIP
    #>

    [CmdletBinding()]
    param(
        # The provider to use to get the public IP address.
        [Parameter()]
        [ValidateScript({ $providerMap.Keys })]
        $Provider = 'IPInfo'
    )

    Invoke-RestMethod -Uri $providerMap[$Provider]
}

Write-Verbose "[$scriptName] - [public] - [Get-PublicIP] - Done"
#endregion - From [public] - [Get-PublicIP]

Write-Verbose "[$scriptName] - [public] - Done"
#endregion - From [public]

#region - From [common]
Write-Verbose "[$scriptName] - [common] - Importing"

$script:providerMap = @{
    MyIP   = 'https://api.myip.com/'
    IPInfo = 'https://ipinfo.io/json'
}
Write-Verbose "[$scriptName] - [common] - Done"
#endregion - From [common]


$exports = @{
    Alias    = '*'
    Cmdlet   = ''
    Function = 'Get-PublicIP'
    Variable = ''
}
Export-ModuleMember @exports