Powershell check if ip or subnet belong to each other


I needed a powershell script today with which i can check if two given IP addresses match or if a given IP address belongs to a subnet or if a smaller subnet belongs to a larger one (or vise vursa). I found a nice script written by Sava from http://www.padisetty.com/ which had part of the functionality i required so i took and modified it to suit my needs. Below you will be able to find the modified script i hope it helps somebody :). The script will return an array of two values, one to indicate true or false and the second the direction.  The direction is important as you may want to compare values for a firewall and as such you want to fit one in the other in a particular direction.

Usage example:

  • checkSubnet ‘’ ‘’
  • checkSubnet ‘’ ‘′
  • checkSubnet ‘’ ‘’


2 thoughts on “Powershell check if ip or subnet belong to each other

  1. hi – Thanks very much for this function. This was perfect and fit-for-purpose where firewall rules are to be checked and validated

Leave a Reply