public/Get-OsQueryIPAddress.ps1

function Get-OsQueryIPAddress {
    <#
    .SYNOPSIS
    Retrieves IP address information from the osquery database.

    .DESCRIPTION
    This function queries the 'interface_addresses' table in the osquery database to retrieve IP address information.

    .PARAMETER Limit
    Specifies the maximum number of IP address records to return. Default is 0.

    .EXAMPLE
    Get-OsQueryIPAddress

    Retrieves all IP address records from the osquery database.

    .EXAMPLE
    Get-OsQueryIPAddress -Limit 25

    Retrieves up to 25 IP address records from the osquery database.

    #>


    [CmdletBinding()]
    param (
        [parameter(Mandatory=$false)][int]$Limit = 0,
        [parameter(Mandatory=$false)][string]$ComputerName
    )

    $tablename = "interface_addresses"

    if ($Limit -gt 0) {
        $query = "SELECT * FROM $tablename LIMIT $Limit;"
    } else {
        $query = "SELECT * FROM $tablename;"
    }
    $invokeParams = @{ Query = $query }
    if (![string]::IsNullOrEmpty($ComputerName)) { $invokeParams.ComputerName = $ComputerName }
    Invoke-OsQueryTableQuery @invokeParams | Select-Object -Property *, @{Name = "tablename"; Expression = { $tablename }}
}