首页 > 解决方案 > 如果免费 IP 高于或低于输入数字,我如何询问 DHCP 范围?(电源外壳)

问题描述

我希望能够在提示符中输入一个数字,并查看我的哪个范围有这么多的空闲 IP 地址。我已经走到这一步了……

     #----------------CODE---------------------
   Write-Host "Enter number off IP-addresses: " -FO blue
   $input = Read-Host
    
    
   $SCOPES = Get-DhcpServerv4Scope
   $count = 0
    
    
   foreach($scope in $SCOPES)
        
     {
    
     $scopeID = $scope.ScopeID
     $freeIP = Get-DhcpServerv4FreeIPAddress -ScopeID $scope.ScopeID -NumAddress 1024
     foreach  ($freeIP in $scope)
         {
         $count ++ 
                 
         }
    
         if($count -lt $input)
             {
                 Write-Host $scopeID " has less than  " $input " free IP addresses." 
             }
                
             elseif($count -gt $input)
                 {
                     Write-Host $scopeID " has more than  " $input " free IP addresses." 
                 }
    
    
      }
   #--------------END OF CODE

但它似乎按预期工作。似乎 scipt 在计算免费 IP 时遇到了麻烦?

提前致谢。

标签: powershell

解决方案


推荐阅读