我希望我的输出给我一个哈希表。
$hashtable @{}
If( $scope | Get-DhcpServerV4Lease -ComputerName $server | Where-Object HostName -like "$hostName*") {$hashtable.add($scope.name, $hostname)}
我相信因为我有嵌套的东西,所以我无法$hashtable
填充。
$DHServers = Get-DhcpServerInDC #get DHCP info
foreach ($Server in $DHServers){
$scopes = Get-DHCPServerv4Scope -ComputerName $Server.dnsname #get all scopes
foreach ($hostname in (Get-Content C:\script\HostNameList.txt)){ #get hostnames from list
foreach ($scope in $scopes){
$hastable = @{} #create hash table
if($scope | Get-DhcpServerV4Lease -ComputerName $server.dnsname | Where-Object HostName -like "$hostName*" ) #compares the hostname to find which lease it is in
{$hashtable.add($scope.name, $hostname)} # add keys, values to table
}
}
}
$hastable