【发布时间】:2015-09-17 20:57:14
【问题描述】:
好的,所以这更像是一个基本的 Powershell 问题,我很确定,但这是我想要做的:
我正在编写一个快速脚本,它读取给定范围内的所有 DHCP 租约,查找客户端名称的任何匹配项(在本例中,名称中包含“iphone”),然后从 DHCP 中删除这些租约。到目前为止,这是我所拥有的:
$leases = Get-DhcpServerv4Lease -ScopeId 192.168.1.0 | select hostname, clientid
#Find all hostnames w/ 'android' or 'iphone' in name, delete lease
$trouble = $leases | select-string -Pattern "android","iphone","ipad"
Remove-DhcpServerv4Lease -ScopeId 192.168.1.0 -ClientId $trouble
问题是 $trouble 的输出现在看起来像这样:
@{hostname=Someones-iPhone.domain.com; clientid=00-00-00-00-c7-cc}
由于我无法根据主机名删除租约(因为我认为这不是全球唯一的),我需要传递 MAC,也就是客户端 ID。
我怎样才能让输出精简到只有 clientid 而没有所有其他数据?我用谷歌搜索了我的心,它没有帮助。提前致谢!
【问题讨论】:
标签: powershell windows-server dhcp