需求:web
DHCP服務器地址池頻繁被Bad_Address垃圾請求打滿;
shell
安全及網絡同事在溯源排錯過程當中,須要及時清理垃圾地址信息,防止新用戶沒法正常獲取IP地址信息;安全
查詢當前做用域信息:服務器
Get-DhcpServerv4Lease -ComputerName 10.78.0.226 -ScopeId 10.78.48.0
查詢當前地址池主機名爲BAD_Address:網絡
Get-DhcpServerv4Lease -ComputerName 10.78.0.226 -ScopeId 10.78.48.0 |where {$_.Hostname -like "BAD*" }
Get-DhcpServerv4Lease語法: Get-DhcpServerv4Lease [-ScopeId] <ipaddress> [<CommonParameters>] Get-DhcpServerv4Lease [<CommonParameters>] Get-DhcpServerv4Lease [-ScopeId] <ipaddress> [-ClientId] <string[]> [<CommonParameters>] Get-DhcpServerv4Lease [[-ScopeId] <ipaddress>] [<CommonParameters>] 描述: 獲取從動態主機配置協議(DHCP)服務器服務的一個或多個租賃記錄。 若是指定ScopeId參數,則返回指定範圍內的活動租約。要得到包括Active,Offered,Declined和Expired在內的各類租約,必須指定AllLeases參數。 若是指定IPAddress參數,則返回指定IP地址的租約記錄。 若是指定ClientId和ScopeId參數,則返回指定範圍內指定ClientId參數值的租約。 若是指定BadLeases和ScopeId參數,則返回指定範圍的全部錯誤租約記錄。 若是指定不帶ScopeId參數的BadLeases參數,則返回DHCP服務器服務中的全部錯誤租約記錄。
批量過濾並清理無效BAD_Address地址釋放地址空間:ide
$Computername = "10.78.0.226" $Scopeid = "10.78.48.0" Import-Module DHCPServer foreach ($Object in Get-DhcpServerv4Lease -ComputerName $Computername -ScopeId $Scopeid ) { if ($object.HostName –like 'BAD_A*') { Remove-DhcpServerv4Lease -ComputerName $Computername -ScopeId $Scopeid -ClientId $object.ClientId } }
語法: Remove-DhcpServerv4Lease [<CommonParameters>] Remove-DhcpServerv4Lease [-ScopeId] <ipaddress> [<CommonParameters>] Remove-DhcpServerv4Lease [-ScopeId] <ipaddress> [-ClientId] <string[]> [<CommonParameters>] Remove-DhcpServerv4Lease [[-ScopeId] <ipaddress>] [<CommonParameters>] 描述: 刪除從動態主機配置協議(DHCP)服務器服務的一個或多個IPv4租約記錄。 若是指定了ScopeId參數,則刪除指定範圍的全部租約。 若是指定了IPAddress參數,則刪除由一個或多個指定IP地址標識的客戶端的租約。若是指定了ClientId和ScopeId參數,則會刪除指定範圍內指定客戶端標識符(ID)的租約。 若是指定了BadLeases和ScopeId參數,則此cmdlet將刪除指定範圍的全部錯誤租約記錄。 若是在沒有ScopeId參數的狀況下指定了BadLeases參數,則此cmdlet將從DHCP服務器服務上的全部做用域中刪除全部錯誤租約。