首先打开PowerShell控制台,当然,PowerShell提供了一个脚本编辑器PowerShell ISE,在PowerShell控制台下输入“PowerShell_ISE”直接调用,将代码拷到ISE中,直接运行脚本代码。(注:PowerShell ISE默认在Windows SERVER 2008 R2上是被安装的)
$dhcpscope=read-host -prompt "请输入DHCP作用域地址"
$scopename=read-host -prompt "请输入DHCP作用域名称"
$iprangA=read-host -prompt "请输入DHCP分配起始地址"
$iprangB=read-host -prompt "请输入DHCP分配终止地址"
$ipgateway=read-host -prompt "请输入DHCP分配的网关地址"
$ipdns=read-host -prompt "请输入DHCP分配的DNS地址"
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 (添加地址作用域)
netsh dhcp server scope $dhcpscope add iprange $iprangeA $iprangeB DHCP (添加DHCP服务中的IP地址范围)
netsh dhcp server scope $dhcpscope set optionvalue 003 ipaddress $ipgateway (分发DHCP的网关地址)
netsh dhcp server scope $dhcpscope set optionvalue 006 ipaddress $ipdns (分发DNS)
netsh dhcp server scope $dhcpscope set state 1