微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我可以做些什么来加速 PowerShell 中嵌套的 DHCP foreach 循环?

如何解决我可以做些什么来加速 PowerShell 中嵌套的 DHCP foreach 循环?

我有 3 个嵌套循环,它们执行以下操作:

  1. 从 DHCP 获取范围
  2. 从 csv 文件获取主机名
  3. 比较主机名和租约,将匹配项添加到哈希表中

有 5 个 DHCP 服务器、100 个范围和数千个租约。

快速度的好方法是什么?

谢谢!

$DHServers = Get-DhcpserverInDC #get DHCP info
$hashtable = @{} #create hash table

foreach ($server in $DHServers){
$scopes = Get-DHcpserverv4Scope -ComputerName $server.dnsname #get all scopes in DHCP   
    
    foreach ($_ in (Import-Csv C:\script\Asset_List.csv | Select-Object -ExpandProperty asset)){ #get hostnames from list          
        
        foreach ($scope in $scopes){            
            if($scope | Get-DhcpserverV4Lease -ComputerName $server.dnsname | Where-Object HostName -like "$_*" ){ #compares the hostname to find which lease it is in
                $scopename=$scope.name #matches give scope name
                $hashtable[$_] = $scopename #when a match is found,add keys and values to table
            } 
        }
    }
}  
  
 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。