Public/Connectivity/Get-InternetConnectionCost.ps1

function Get-InternetConnectionCost {
    <#
.SYNOPSIS
    Retrieves the cost information for the current internet connection profile.
 
.DESCRIPTION
    The `Get-NetworkConnectionCost` function retrieves the active internet connection profile
    and outputs cost-related information such as the network cost type, roaming status, and
    whether the connection is approaching its data limit.
 
    While this can be useful for Wi-Fi networks, it also applies to any network connection
    (e.g., cellular, Ethernet, etc.).
 
.PARAMETER None
    This function does not take any parameters.
 
.EXAMPLE
    Get-NetworkConnectionCost
    Retrieves and displays the cost information for the current internet connection.
 
.NOTES
    - The function works with the `GetInternetConnectionProfile()` method to retrieve the active connection.
    - If no internet connection profile is found, a warning is displayed.
#>

    [OutputType([Windows.Networking.Connectivity.ConnectionCost])]
    param()
    process {
        # Get the current Internet connection profile
        $InternetConnectionProfile = [Windows.Networking.Connectivity.NetworkInformation]::GetInternetConnectionProfile()
        if ($null -eq $InternetConnectionProfile) {
            Write-Warning "No internet connection profile found."
            return
        }
        # Get the ConnectionCost object
        $cost = $InternetConnectionProfile.GetConnectionCost()
        # Output relevant properties
        [PSCustomObject]@{
            ProfileName            = $InternetConnectionProfile.ProfileName
            NetworkCostType        = $cost.NetworkCostType
            IsOverDataLimit        = $cost.ApproachingDataLimit
            IsRoaming              = $cost.Roaming
            IsApproachingDataLimit = $cost.ApproachingDataLimit
        }
    }
}