Last active
May 27, 2016 13:15
-
-
Save Barmp/c2570b9cf65f5463d2ac to your computer and use it in GitHub Desktop.
Reconfigures DHCP Scope Exclusions en masse.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
# MIT License | |
# Copyright (c) 2016 Greg Malone | |
# | |
# Commands to remove and replace all exclusion ranges on two DHCP servers. | |
# Assumes a split scope configuration and adds a delay to backup server. | |
# I ran this manually, instead of as a script, so YMMV. | |
### | |
# Create remote sessions to DHCP servers. | |
$srv01 = New-PSSession -ComputerName dhcpsrv01 -Name DHCPSRV01 | |
$srv02 = New-PSSession -ComputerName dhcpsrv02 -Name DHCPSRV02 | |
#DHCPSRV02 commands (Backup) | |
Enter-PSSession $srv02 | |
$exclusions = Import-Csv C:\Users\administrator\Documents\dhcpsrv02_exclusionrange.csv # configurations CSV previously moved to local documents folder. | |
# Set DHCP Scopes to inactive prior to reconfiguration. | |
Get-DhcpServerv4Scope | Set-DhcpServerv4Scope -State InActive | |
# Remove all exclusion ranges from DHCP scopes. | |
Get-DhcpServerv4ExclusionRange | Remove-DhcpServerv4ExclusionRange | |
# Set Delay on all DHCP Scopes of 500ms. | |
Get-DhcpServerv4Scope | Set-DhcpServerv4Scope -Delay 500 | |
Invoke-Command { | |
foreach ($Scope in $exclusions) { | |
$ID = $Scope.ScopeId | |
$Startrange = $Scope.StartRange | |
$Endrange = $Scope.EndRange | |
Add-DhcpServerv4ExclusionRange -ScopeId $ID -StartRange $Startrange -EndRange $Endrange | |
} | |
} | |
# Reactivate all scopes | |
Get-DhcpServerv4Scope | Set-DhcpServerv4Scope -State Active | |
Exit-PSSession | |
#DHCPSRV01 commands | |
Enter-PSSession $srv01 | |
$exclusions = Import-Csv C:\Users\administrator\Documents\dhcpsrv01_exclusionrange.csv # configurations CSV previously moved to local documents folder. | |
# Set DHCP Scopes to inactive prior to reconfiguration. | |
Get-DhcpServerv4Scope | Set-DhcpServerv4Scope -State InActive | |
# Remove all exclusion ranges from DHCP scopes. | |
Get-DhcpServerv4ExclusionRange | Remove-DhcpServerv4ExclusionRange | |
Invoke-Command { | |
foreach ($Scope in $exclusions) { | |
$ID = $Scope.ScopeId | |
$Startrange = $Scope.StartRange | |
$Endrange = $Scope.EndRange | |
Add-DhcpServerv4ExclusionRange -ScopeId $ID -StartRange $Startrange -EndRange $Endrange | |
} | |
} | |
# Reactivate all scopes | |
Get-DhcpServerv4Scope | Set-DhcpServerv4Scope -State Active | |
Exit-PSSession | |
Remove-PSSession -Name DHCPSRV01 | |
Remove-PSSession -Name DHCPSRV02 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ScopeId | StartRange | EndRange | |
---|---|---|---|
192.168.1.0 | 192.168.1.51 | 192.168.1.184 | |
192.168.1.0 | 192.168.1.220 | 192.168.1.254 | |
192.168.1.0 | 192.168.1.1 | 192.168.1.50 | |
192.168.10.0 | 192.168.10.51 | 192.168.10.184 | |
192.168.10.0 | 192.168.10.220 | 192.168.10.254 | |
192.168.10.0 | 192.168.10.1 | 192.168.10.50 | |
192.168.11.0 | 192.168.11.1 | 192.168.11.105 | |
192.168.11.0 | 192.168.11.106 | 192.168.11.114 | |
192.168.11.0 | 192.168.11.120 | 192.168.11.254 | |
192.168.12.0 | 192.168.12.51 | 192.168.12.184 | |
192.168.12.0 | 192.168.12.220 | 192.168.12.254 | |
192.168.12.0 | 192.168.12.1 | 192.168.12.50 | |
192.168.13.0 | 192.168.13.51 | 192.168.13.149 | |
192.168.13.0 | 192.168.13.200 | 192.168.13.254 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment