PowerShell快速查看和绑定DHCP用户

要求 DHCP的PowerShell为4.0 2012 R2系统

这个脚本可以方便SCO以及编程中调用,可以做成审批流,方便用户提交绑定IP的申请。

Get-DhcpServerv4Lease-ComputerNamedc.contoso.com-IPAddress192.168.136.25|selectIPAddress,hostname,addressstate,leaseexpirytime#以上语句获取192.168.136.25这个IP在DHCP服务器(dc.contoso.com)中的属性Get-DhcpServerv4Scope-ComputerNamedc.contoso.com|Get-DhcpServerv4Lease-ComputerNamedc.contoso.com|selectIPAddress,hostname,addressstate#获取服务器下所有作用域中的IP地址,并简单筛选一下Get-DhcpServerv4Lease-ComputerNamedc.contoso.com-IPAddress192.168.136.25|Set-DhcpServerv4Reservation获取192.168.136.25的相关信息,,并用相应描述信息绑定之Get-DhcpServerv4Lease-ComputerNamedc.contoso.com-IPAddress192.168.136.25|selectIPAddress,hostname,addressstate,leaseexpirytime#再次查看一下所有作用域中的IP

可以加一些变量,方便管理员来处理,比如

$a=Read-Host(“请输入位于dc.contoso.com上的,需要绑定的IP地址,类似XXX.XXX.XXX.XXX”)Get-DhcpServerv4Lease-ComputerNamedc.contoso.com-IPAddress$a|Set-DhcpServerv4Reservation

当然上面这个脚本也可以修改一下,适应不同的IP范围,也就是指定不同的服务器名称。那么这个就稍微麻烦一点,需要用户输入作用于范围,或者自己定义一些属性值,比如可以用类似下面的switch语句

$zone1=Read-Host(“请选择员工所处区域:(1)北京,(2)腾达,(3)广州,(4)上海,(5)成都,(6)西安:”)switch($zone1){1{$zone2=”北京”}2{$zone2=”腾达”}3{$zone2=”广州”}4{$zone2=”上海”}5{$zone2=”成都”}6{$zone2=”西安”}}

本文出自 “九叔-微软私有云” 博客,请务必保留此出处

深重如溺入蓝色的海洋,无法呼吸。

PowerShell快速查看和绑定DHCP用户

相关文章:

你感兴趣的文章:

标签云: