windos 2012 dhcp服务器使用脚本批量创建作用域

地址池设置 租期:天.小时:分钟:秒
Add-DhcpServerv4Scope -name " 地址池名称 " -StartRange 地址池起始地址 -EndRange 地址池结束地址 -SubnetMask 子网掩码 -State Active -LeaseDuration 4.00:00:00
Add-DhcpServerv4Scope -name " vlan10 " -StartRange 172.20.10.21 -EndRange 172.20.10.254 -SubnetMask 255.255.255.0 -State Active -LeaseDuration 4.00:00:00
Add-DhcpServerv4Scope -name "vlan10" -StartRange 172.20.10.21 -EndRange 172.20.10.254 -SubnetMask 255.255.255.0 -State Active -LeaseDuration 4.00:00:00

网关设置
Set-DhcpServerv4OptionValue -OptionID 3 -Value 网关IP -ScopeID 网络号
Set-DhcpServerv4OptionValue -OptionID 3 -Value 172.20.10.1 -ScopeID 172.20.10.0

DNS设置
Set-DhcpServerv4OptionValue -DnsDomain 域名 -DnsServer DNS服务器1,DNS服务器2 -ScopeId 网络号
Set-DhcpServerv4OptionValue -DnsDomain free.com -DnsServer 172.20.200.21,172.20.200.22 -ScopeId 172.20.10.0

设置无线AP管理DHCP 43选项:
Set-DhcpServerv4OptionValue -OptionID 43 -Value 0x03,0x0E,0x31,0x30,0x2E,0x31,0x30,0x39,0x2E,0x31,0x34,0x30,0x2E,0x31,0x33,0x34 -ScopeID 192.168.8.0

设置电话tftp 6选项
Set-DhcpServerv4OptionValue -OptionID 66 -Value "tftp://192.168.20.38" -ScopeID 192.168.8.0

$Scopes = Get-DhcpServerv4Scope -ComputerName  Sername
$ScopeNames = $Scopes.Name
foreach ( $ScopeName in $ScopeNames ){ write-Host $ScopeName }

Get-DhcpServerv4Scope 

 Remove-DhcpServerv4OptionValue -OptionID 67 -ScopeID 192.168.163.0
获取 IP 和mac地址
Get-DhcpServerv4Lease -ComputerName TM19-DHCP01 -ScopeId 192.168.1.0  | Select-Object IPAddress, ClientId | Format-Table -AutoSize


IPAddress     ClientId         
---------     --------         
192.168.1.1 aa-bb-cc-ee-ff-00
192.168.1.2 aa-bb-cc-ee-ff-01
-----------------------------------------------------------------
导入powershell
Import-Csv -Path C:\01-powershell\list.csv | Add-DhcpServerv4Reservation -ComputerName DHCP-hostname

C:\01-powershell\list.csv
ScopeId,IPAddress,Name,ClientId,Description
192.168.1.0,192.168.1.1,dev_name,aa-bb-cc-ee-ff-00,Reserved for dev
192.168.1.0,192.168.1.2,dev_name,aa-bb-cc-ee-ff-01,Reserved for dev
#批量创建dhcp 网段
$users=Import-Csv C:\01-powershell\net.csv
foreach ($user in $users){
Add-DhcpServerv4Scope -name $user.name -StartRange $user.ip1 -EndRange $user.ip250  -SubnetMask 255.255.255.0 -State Active  -LeaseDuration 0.04:00:00
Set-DhcpServerv4OptionValue -OptionID 3 -Value $user.ip254  -ScopeID  $user.net
Set-DhcpServerv4OptionValue -DnsDomain test.cn -DnsServer 192.168.1.1,192.168.1.2 -ScopeId $user.net
}

C:\01-powershell\net.csv 文件如下:
name,ip1,ip250,ip254,net
test_Pool_V13,192.168.13.1,192.168.13.250,192.168.13.254,192.168.13.0
test_Pool_V14,192.168.14.1,192.168.14.250,192.168.14.254,192.168.14.0
test_Pool_V15,192.168.15.1,192.168.15.250,192.168.15.254,192.168.15.0
test_Pool_V16,192.168.16.1,192.168.16.250,192.168.16.254,192.168.16.0
test_Pool_V17,192.168.17.1,192.168.17.250,192.168.17.254,192.168.17.0
test_Pool_V18,192.168.18.1,192.168.18.250,192.168.18.254,192.168.18.0
test_Pool_V19,192.168.19.1,192.168.19.250,192.168.19.254,192.168.19.0
test_Pool_V20,192.168.20.1,192.168.20.250,192.168.20.254,192.168.20.0
test_Pool_V21,192.168.21.1,192.168.21.250,192.168.21.254,192.168.21.0
test_Pool_V22,192.168.22.1,192.168.22.250,192.168.22.254,192.168.22.0
test_Pool_V23,192.168.23.1,192.168.23.250,192.168.23.254,192.168.23.0
test_Pool_V24,192.168.24.1,192.168.24.250,192.168.24.254,192.168.24.0
test_Pool_V25,192.168.25.1,192.168.25.250,192.168.25.254,192.168.25.0
test_Pool_V26,192.168.26.1,192.168.26.250,192.168.26.254,192.168.26.0
test_Pool_V27,192.168.27.1,192.168.27.250,192.168.27.254,192.168.27.0
test_Pool_V28,192.168.28.1,192.168.28.250,192.168.28.254,192.168.28.0
test_Pool_V29,192.168.29.1,192.168.29.250,192.168.29.254,192.168.29.0
test_Pool_V30,192.168.30.1,192.168.30.250,192.168.30.254,192.168.30.0


posted @ 2021-09-26 18:51  Ant·Hanks  阅读(217)  评论(0编辑  收藏  举报