$dhcpscope=read-host -Prompt “请输入dhcp作用域地址”
$scopename=Read-Host -Prompt “请输入dhcp作用域名称”
$scopedescript=Read-Host -Prompt “请输入dhcp作用域的描述”
#获取当前计算机名#
$Hostname=$env:COMPUTERNAME
#获取本机的完全合格域名#
$fqdnname=([system.net.dns]::gethostentry($Hostname)).Hostname
$iprangea=Read-Host -Prompt “请输入dhcp分配起始地址”
$iprangeb=Read-Host -Prompt “请输入dhcp分配结束地址”
$ipexcludea=Read-Host -Prompt “请输入dhcp排除起始地址”
$ipexcludeb=Read-Host -Prompt “请输入dhcp排除结束地址”
$ipgateway=Read-Host -Prompt “请输入dhcp分配的网关地址”
$ipdns=Read-Host -Prompt “请输入dhcp分配的dns地址”
#在windows server 2008中自动安装DHCP服务#
ServerManagercmd -i dhcp
#对DHCP服务启动模式设置为自动#
Get-Service dhcpserver |Set-Service -StartupType automatic
#启动DHCP服务#
Start-Service dhcpserver
#添加地址作用域#
netsh dhcp server add scope $dhcpscope 255.255.255.0 $scopename $scopedescript
#在活动目录中添加DHCP服务授权#
netsh dhcp add server $fqdnname
#添加DHCP服务中的IP地址范围#
netsh dhcp server scope $dhcpscope add iprange $iprangea $iprangeb dhcp
#在分发域中添加排除地址#
netsh dhcp server scope $dhcpscope add excluderange $ipexcludea $ipexcludeb
#在DHCP服务中添加分发网关地址#
netsh dhcp server scope $dhcpscope set optionvalue 003 ipaddress $ipgateway
#在DHCP服务中添加DNS地址#
netsh dhcp server scope $dhcpscope set optionvalue 006 ipaddress $ipdns
#激活DHCP分发域#
netsh dhcp server scope $dhcpscope set state 1
原创文章,作者:carmelaweatherly,如若转载,请注明出处:https://blog.ytso.com/tech/safety/219550.html