Functions/RemotePS/Get-IpAddressFromHostname.ps1

<#
.SYNOPSIS
    Returns one IPv4 address of the machine supplied in the hostname parameter.
.DESCRIPTION
    Queries the DNS server for the IPv4 or IPv6 address of the supplied hostname and returns the first IP address found. Default the first IPv4 address is returned. Use the switch IPv6 to get the IPv4 address. Use the switch All to get all known IPv4 or IPv6 addresses for the hostname)
.EXAMPLE
    Get-IpAddressFromHostname -Hostname 'REL017NL.4ps.nl'
.EXAMPLE
    Get-IpAddressFromHostname -Hostname 'www.google.nl' -IPv6 -All
#>

function Get-IpAddressFromHostname {
    [OutputType([String[]])]
    Param (      
        # Hostname of the machine to get the IP address for.
        [Parameter(Mandatory=$true, Position=0)]
        [ValidateNotNullOrEmpty()]
        [string]
        $Hostname,
        
        # Default this cmdlet returns a IPv4 address, use this switch to get the IPv6 address of the hostname.
        [Parameter(Mandatory=$false, Position=1)]
        [switch]
        $IPv6,

        # Use this switch to get all registered IPv4 or IPv6 addresses for the specified hostname. Default this cmdlet returns only the first IP address.
        [Parameter(Mandatory=$false, Position=2)]
        [switch]
        $All
    )

    if ($IPv6) {
        $IPType = 'AAAA' # IPv6
    } else {
        $IPType = 'A'    # IPv4
    }

    if ($All) {
        (Resolve-DNSName $Hostname | Where-Object {$_.Type -eq $IPType} | Select-Object -Property IPAddress).IPAddress
    } else {
        (Resolve-DNSName $Hostname | Where-Object {$_.Type -eq $IPType} | Select-Object -Property IPAddress -First 1).IPAddress
    }
}

Export-ModuleMember -Function Get-IpAddressFromHostname