这是我的输出的样子,它只是主机名所在的租约信息:
IPAddress ScopeId ClientId HostName AddressState
--------- ------- -------- -------- ------------
10.10.10.10 99.99.99.99 11-11-11-11-11-11 AL10 Active
使用此 PowerShell 脚本:
$hostname = "AL10"
$locationArray = @()
foreach ($Server in $DHServers){
$scope = Get-DHCPServerv4scope -ComputerName $Server.dnsname | Get-DHCPServerv4Lease -ComputerName $Server.dnsname | Where-Object HostName -like "$hostName*"
$locationArray += $scope
}
$locationArray
我想要的是,它只是输出:
ScopeID Name
---------
Name
目标是:提供一个.txt的主机名,找到对应的DHCP Server租约,然后像使用时一样输出ScopeID的“名称”Get-DHCPServerv4scope -ComputerName $Server.dnsname | Select-Object "name"