|
要求 DHCP的PowerShell为4.0 2012 R2系统
这个脚本可以方便SCO以及编程中调用,可以做成审批流,方便用户提交绑定IP的申请。
1
2
3
4
5
6
7
8
9
| Get-DhcpServerv4Lease -ComputerName dc.contoso.com -IPAddress 192.168.136.25|select IPAddress,hostname,addressstate,leaseexpirytime
#以上语句获取192.168.136.25这个IP在DHCP服务器(dc.contoso.com)中的属性
Get-DhcpServerv4Scope -ComputerName dc.contoso.com | Get-DhcpServerv4Lease -ComputerName dc.contoso.com|select IPAddress,hostname,addressstate
#获取服务器下所有作用域中的IP地址,并简单筛选一下
Get-DhcpServerv4Lease -ComputerName dc.contoso.com -IPAddress 192.168.136.25|Set-DhcpServerv4Reservation
获取192.168.136.25的相关信息,并用相应描述信息绑定之
Get-DhcpServerv4Lease -ComputerName dc.contoso.com -IPAddress 192.168.136.25|select IPAddress,hostname,addressstate,leaseexpirytime
#再次查看一下所有作用域中的IP
|
可以加一些变量,方便管理员来处理,比如
1
2
| $a = Read-Host("请输入位于dc.contoso.com上的,需要绑定的IP地址,类似XXX.XXX.XXX.XXX")
Get-DhcpServerv4Lease -ComputerName dc.contoso.com -IPAddress $a|Set-DhcpServerv4Reservation
|
当然上面这个脚本也可以修改一下,适应不同的IP范围,也就是指定不同的服务器名称。那么这个就稍微麻烦一点,需要用户输入作用于范围,或者自己定义一些属性值,比如可以用类似下面的switch语句
1
2
3
4
5
6
7
8
9
| $zone1 = Read-Host("请选择员工所处区域:(1)北京,(2)腾达,(3)广州,(4)上海,(5)成都,(6)西安: ")
switch ($zone1) {
1 {$zone2 = "北京"}
2 {$zone2 = "腾达"}
3 {$zone2 = "广州"}
4 {$zone2 = "上海"}
5 {$zone2 = "成都"}
6 {$zone2 = "西安"}
}
|
|
|