如何解决我可以做些什么来加速 PowerShell 中嵌套的 DHCP foreach 循环?
我有 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 举报,一经查实,本站将立刻删除。