PowerShell Script: Calculate First and Last IP of a Subnet

I just wrote this script to calculate the first and last IP of a subnet based on any given IP (within the subnet) and it’s subnet mask:

Syntax: .\Get-NetworkStartEndAddress.ps1 “IP address” “Subnet Mask”

Download here: Get-NetworkStartEndAddress.ps1


  1. Good script! Thanks for putting it together. We use the first IP for default gateways and this makes automating our IP assignment process much easier.

  2. Thanks a lot for the useful script, saved me a lot of work
    Just one caveat, at the end of validate-subnetmask you are doing:
    ((($strFullBinary.plit(“.”)).count -ne 2))
    I believe that you replace the comparator with -gt instead of -ne

    WHY: because the -ne will consider invalid the subnet mask (single system)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: