Created
March 25, 2021 15:36
-
-
Save iyre/ddf1551d33295b3cad89893e24a9d0f6 to your computer and use it in GitHub Desktop.
Update the subnet mask for an existing DHCP scope
This file contains hidden or 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
$ServerName = "CORP-DHCP01" | |
$ScopeId = "10.10.10.0" | |
$SubnetMask = "255.255.255.0" #This is the NEW mask that will be applied | |
$ServerFile = "c:\temp\dhcp_backup.xml" | |
$ServerFileBackup = "c:\temp\dhcp_backup2.xml" | |
$ScopeFile = "c:\temp\scope_$ScopeId.xml" | |
#backup entire server, just in case | |
Export-DhcpServer -ComputerName $ServerName -Leases -File $ServerFile | |
Export-DhcpServer -ComputerName $ServerName -ScopeId $ScopeId -Leases -File $ScopeFile | |
#force to remove superscope if necessary | |
Remove-DhcpServerv4Scope -ComputerName $ServerName -ScopeId $ScopeId -Force | |
#update the subnet mask in the exported scope | |
[xml]$ScopeXml = Get-Content $ScopeFile | |
$ScopeXml.DHCPServer.IPv4.Scopes.Scope.SubnetMask = $SubnetMask | |
$ScopeXml.Save($ScopeFile) | |
#import modified scope after backing up current config (required) | |
Import-DhcpServer -ComputerName $ServerName -ScopeId $ScopeId -Leases -File $ScopeFile -BackupPath $ServerFileBackup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment