-
Notifications
You must be signed in to change notification settings - Fork 0
/
IPincrementer.ps1
45 lines (37 loc) · 1.5 KB
/
IPincrementer.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<#
.SYNOPSIS
Increment IP addressed for your scripts
.DESCRIPTION
This will use the split function of the powershell to split the ip addresses by . and then increments the last octet and joins them.
This might come in handy if you want to perform a certain number of action on a range of ip addresses in a script.
This is rather an adaptation of the ip incrementer script by LUCD who is a powercli and powershell guru and
extremely active on vmware communities. All credits to him.
.NOTES
File Name : IPincrementer.ps1
Author : LUCD, gajendra d ambi
Date : Jan 2015
Prerequisite : PowerShell V2 over Vista and upper.
Copyright - None
.LINK
Script posted over:
https://github.com/gajuambi/windows
#>
#start of script
#let's get the 1st ip address
$host1 = Read-Host "type the 1st ip address"
#Then let us have the number of ip addresses that you want
$max = Read-Host "Maximum nubmer of ip addresses?"
#now split that ip address and retain the 1st 3 octets which will be fixed
$fixed = $host1.Split('.')[0..2]
#now let us have the last octet of the host's ip address
$last = [int]($host1.Split('.')[3])
#let us subtract 1 from the maximum number of IPs that we want since it counts from 0
$max_hosts = $max - 1
#now let us increment the $last octet with a +1 till we get $max_hosts of ip addresses
$hosts =
$last..($last + $max_hosts) | %{
[string]::Join('.',$fixed) + "." + $_
}
#now let us print the results to the screen
$hosts
#End of script