Si vous avez installé le rôle "Services de domaine Active Directory", alors le rôle Serveur DHCP est déjà installé.
Get-Service -Name DHCPServer
Install-WindowsFeature -Name DHCP -IncludeManagementTools
Import-Module DhcpServer
netsh dhcp add securitygroups
Start-Service -Name DHCPServer
Set-Service -Name DHCPServer -StartupType Automatic
Une « étendue DHCP » (ou DHCP scope) désigne la plage d'adresses IP qu'un serveur DHCP peut attribuer automatiquement aux clients d'un réseau.
Lors de la création d'une étendue DHCP, il faut définir :
Il s'agit simplement d'un libellé qui permet de distinguer facilement l'étendue dans la console de gestion (par exemple « Scope Réseau 192.168.1.0 »).
(copiez/collez le bloc ci-dessous directement)
$nameEtendue = Read-Host -Prompt "ENTREZ UN NOM POUR L'ETENDUE DHCP A CREER (ex : Etendue-NAT)"
$startRange = Read-Host -Prompt "ENTREZ L'ADRESSE IP DE DEPART DE L'ETENDUE (ex : 10.10.10.2)"
$endRange = Read-Host -Prompt "ENTREZ L'ADRESSE IP DE FIN DE L'ETENDUE (ex : 10.10.10.200)"
$subnetMask = Read-Host -Prompt "ENTREZ LE MASQUE RESEAU DE L'ETENDUE (ex : 255.255.255.0)"
$gatewayEtendue = Read-Host -Prompt "ENTREZ L'ADRESSE IP DE LA PASSERELLE DE L'ETENDUE (ex : 10.10.10.1)"
$dns1 = Read-Host -Prompt "ENTREZ LE DNS 1 (ex : 1.1.1.1)"
$dns2 = Read-Host -Prompt "ENTREZ LE DNS 2 (ex : 8.8.8.8)"
Add-DhcpServerv4Scope -Name "$($nameEtendue)" -StartRange "$($startRange)" -EndRange "$($endRange)" -SubnetMask "$($subnetMask)" -State Active
Start-Sleep -Seconds 2
Set-DhcpServerv4OptionValue -OptionId 3 -Value "$($gatewayEtendue)"
Set-DhcpServerv4OptionValue -OptionId 6 -Value "$($dns1)", "$($dns2)"
Get-DhcpServerv4Scope
Get-DhcpServerv4OptionValue