Quantcast
Channel: Easy In IT
Viewing all articles
Browse latest Browse all 10

Create DHCP Scope

$
0
0

I am migrating from none Windows to Windows 2012R2 DHCP, so I needed to install and configure more than 10 DHCP servers.
Each of the DHCP servers would contain several scopes with custom options for ip phones and thin clients. Rather than
clicking trough the GUI every time, I create this script.

When you run this script, it installs the DHCP feature, authorize the DHCP server in AD, sets conflict detection to 2,
creates predefined options 242 and 161 and it creates five scopes.

You only need to active the scopes.

#Install authorize, configure conflict detection and create custom options option for Avaya phones and Wise clients
Install-WindowsFeature -Name DHCP -IncludeManagementTools
Add-DhcpServerInDC
Restart-Service DHCPServer
Set-DhcpServerSetting -ConflictDetectionAttempts 2
Add-DhcpServerv4OptionDefinition -Name "Avaya Option 242" -OptionId 242 -Type String -Description "Avaya Option 242"
Add-DhcpServerv4OptionDefinition -Name "Default FTP Server" -OptionId 161 -Type String -Description "Default FTP Server"

#Create-DHCPScope function
function Create-DHCPScope {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string]$Description,
        [Parameter(Mandatory=$true)]
        [string]$Name,
        [Parameter(Mandatory=$true)]
        [string]$StartIP,
        [Parameter(Mandatory=$true)]
        [ipaddress]$EndIP,
        [Parameter(Mandatory=$true)]
        [ipaddress]$Subnet,
        [Parameter(Mandatory=$true)]
        [ipaddress]$Router,
        [Parameter(Mandatory=$true)]
        [string]$DomainName,
        [Parameter(Mandatory=$true)]
        [ipaddress[]]$DNS,
        [Parameter(Mandatory=$true)]
        [AllowEmptyString()]
        [string]$Option242,
        [Parameter(Mandatory=$true)]
        [AllowEmptyString()]
        [string]$Option161
    )
    PROCESS {
        Add-DhcpServerv4Scope -Name $Name -Description $Description -StartRange $StartIP -EndRange $EndIP -SubnetMask $Subnet -State InActive
        $ScopeID = Get-DhcpServerv4Scope | Where-Object -Property Name -EQ $Name | Select-Object -ExpandProperty ScopeID
        Set-DhcpServerv4OptionValue -ScopeId $ScopeID -Router $Router -DnsDomain $DomainName -DnsServer $DNS -Force
        if ($Option242 -ne ""){
            Set-DhcpServerv4OptionValue -ScopeId $ScopeID -OptionId 242 -Value $Option242
        }
        if ($Option161 -ne ""){
            Set-DhcpServerv4OptionValue -ScopeId $ScopeID -OptionId 161 -Value $Option161
        }
    }
}


#Define Office LAN Scope
$Description = "Office LAN"
$Name = "Office_LAN"
[ipaddress]$StartIP = "192.168.0.100"
[ipaddress]$EndIP = "192.168.0.200"
[ipaddress]$Subnet = "255.255.255.0"
[ipaddress]$Router = "192.168.0.254"
$DomainName = "contoso.com"
[ipaddress[]]$DNS = "192.168.0.10" , "192.168.0.11"
$Option242 = "L2QVLAN=55"
$Option161 = "wyse-client.contoso.com"
#Call the Create-DHCPScope function
Create-DHCPScope -Description $Description -Name $Name -StartIP $StartIP -EndIP $EndIP -Subnet $Subnet -Router $Router -DomainName $DomainName -DNS $DNS -Option242 $Option242 -Option161 $Option161

#Define Development LAN Scope
$Description = "Development LAN"
$Name = "DEV_LAN"
[ipaddress]$StartIP = "192.168.100.100"
[ipaddress]$EndIP = "192.168.100.200"
[ipaddress]$Subnet = "255.255.255.0"
[ipaddress]$Router = "192.168.100.254"
$DomainName = "development.lab"
[ipaddress[]]$DNS = "192.168.100.10" , "192.168.100.11"
$Option242 = ""
$Option161 = ""
#Call the Create-DHCPScope function
Create-DHCPScope -Description $Description -Name $Name -StartIP $StartIP -EndIP $EndIP -Subnet $Subnet -Router $Router -DomainName $DomainName -DNS $DNS -Option242 $Option242 -Option161 $Option161


#Define Office VOIP Scope
$Description = "Office VOIP"
$Name = "Office_VOIP"
[ipaddress]$StartIP = "192.168.50.100"
[ipaddress]$EndIP = "192.168.50.200"
[ipaddress]$Subnet = "255.255.255.0"
[ipaddress]$Router = "192.168.50.254"
$DomainName = "contoso.com"
[ipaddress[]]$DNS = "192.168.0.10" , "192.168.0.11"
$Option242 = "MCIPADD=192.168.50.50,httpsrvr=192.168.0.50,"
$Option161 = ""
#Call the Create-DHCPScope function
Create-DHCPScope -Description $Description -Name $Name -StartIP $StartIP -EndIP $EndIP -Subnet $Subnet -Router $Router -DomainName $DomainName -DNS $DNS -Option242 $Option242 -Option161 $Option161 

#Define Wifi-Guest Scope
$Description = "Wifi Guest"
$Name = "Wifi_Guest"
[ipaddress]$StartIP = "10.0.0.100"
[ipaddress]$EndIP = "10.0.0.200"
[ipaddress]$Subnet = "255.255.255.0"
[ipaddress]$Router = "10.0.0.254"
$DomainName = "guest.wifi"
[ipaddress[]]$DNS = "8.8.8.8"
$Option242 = ""
$Option161 = ""
#Call the Create-DHCPScope function
Create-DHCPScope -Description $Description -Name $Name -StartIP $StartIP -EndIP $EndIP -Subnet $Subnet -Router $Router -DomainName $DomainName -DNS $DNS -Option242 $Option242 -Option161 $Option161

#Define Wifi-LAN Scope
$Description = "Wifi Office"
$Name = "Wifi_Office"
[ipaddress]$StartIP = "10.10.10.100"
[ipaddress]$EndIP = "10.10.10.200"
[ipaddress]$Subnet = "255.255.255.0"
[ipaddress]$Router = "10.10.10.254"
$DomainName = "contoso.com"
[ipaddress[]]$DNS = "192.168.0.10" , "192.168.0.11"
$Option242 = ""
$Option161 = "wyse-client.contoso.com"
#Call the Create-DHCPScope function
Create-DHCPScope -Description $Description -Name $Name -StartIP $StartIP -EndIP $EndIP -Subnet $Subnet -Router $Router -DomainName $DomainName -DNS $DNS -Option242 $Option242 -Option161 $Option161

 


Viewing all articles
Browse latest Browse all 10

Trending Articles