Determines if two IP addresses are on the same subnet.
    This function determines if two IP addresses given in the 'Address/Subnet' or 'Address/MaskLength' format belong to the same subnet, i.e. are able to reach each others without going through the gateway.
    If the subnet masks are different, the smaller subnet will determine the result.
    .PARAMETER IPAddress1
    First IP address for comparison.
    .PARAMETER IPAddress2
    Second IP address for comparison.
    Test-IPv4SameSubnet -IPAddress1 '' -IPAddress2 ''
    Returns a complete subnet definition, without geoinformation, for the specified address.
    None. This cmdlet does not accept pipeline input.

function Test-IPv4SameSubnet {
    $IPresolved1 = Resolve-IPv4Address -IPAddress $IPAddress1
    if ($null -ne $IPresolved1) {
        Write-Verbose "IPAddress1 resolved to $($IPresolved1.Subnet)/$($IPresolved1.SubnetMaskLength)"
    } else {
        Write-Verbose "IPAddress1 could not be resolved"
    $IPresolved2 = Resolve-IPv4Address -IPAddress $IPAddress2
    if ($null -ne $IPresolved2) {
        Write-Verbose "IPAddress2 resolved to $($IPresolved2.Subnet)/$($IPresolved2.SubnetMaskLength)"
    } else {
        Write-Verbose "IPAddress1 could not be resolved"
    $result = $false
    if (($null -ne $IPresolved1) -and ($null -ne $IPresolved2)) {
        if ($IPresolved1.IPAddress -eq $IPresolved2.IPAddress) {
            Write-Verbose "Samer IP address!"
            $result = $true
        } elseif ($IPresolved1.SubnetMaskLength -eq $IPresolved2.SubnetMaskLength) {
            if ($IPresolved1.Subnet -eq $IPresolved2.Subnet) {
                Write-VErbose "Same mask length, same subnet"
                $result = $true
            } else {
                Write-VErbose "Same mask length, different subnet"
        } else {
            if ($IPresolved1.SubnetMaskLength -gt $IPresolved2.SubnetMaskLength) {
                $subnetMaskLength = $IPresolved1.SubnetMaskLength
                $subnet1 = $IPresolved1.Subnet
                $subnet2 = (Resolve-IPv4Address "$($IPresolved2.IPAddress)/$subnetMaskLength").Subnet
                Write-Verbose "Subnet mask 1 is shorter, expanding subnet 2 to $($subnet2)/$subnetMaskLength"
            } else {
                $subnetMaskLength = $IPresolved2.SubnetMaskLength
                $subnet1 = $IPresolved2.Subnet
                $subnet2 = (Resolve-IPv4Address "$($IPresolved1.IPAddress)/$subnetMaskLength").Subnet
                Write-Verbose "Subnet mask 2 is shorter, expanding subnet 1 to $($subnet2)/$subnetMaskLength"
            if ($subnet1 -eq $subnet2) {
                Write-Verbose "Subnets match!"
                $result = $true
    return $result