检索DHCP范围

时间:2017-11-28 17:01:27

标签: powershell scope dhcp

我的脚本在本地运行时工作,我试图从远程服务器获取所有DHCP范围信息,我收到脚本下面的错误

$A = "TestDH01"
ForEach ($B in $A) {

Get-DHCPServerv4Lease -ScopeID $_.ScopeID -AllLeases | where 
{$_.AddressState -like '*Reservation'}

} Select-Object ScopeId,IPAddress,HostName,ClientID,AddressState | ExportCsv "\\TermServer\d$\New\Steve\$($A)-Reservations1.csv" -NoTypeInformation
  

Get-DhcpServerv4Lease:无法验证参数的参数   'ScopeId'。参数为null或空。提供一个参数   不为null或为空,然后再次尝试该命令。在行:4 char:36   + Get-DHCPServerv4Lease -ScopeID $ .ScopeID -AllLeases |其中{$ 。 ...   + ~~~~~~~~~~       + CategoryInfo:InvalidData:(:) [Get-DhcpServerv4Lease],ParameterBindingValidationException       + FullyQualifiedErrorId:ParameterArgumentValidationError,Get-DhcpServerv4Lease

1 个答案:

答案 0 :(得分:0)

我假设你正在寻找这样的东西:

#Get all DHCP Servers
$ServerList = Get-DhcpServerInDC | select IPADdress, DNSName
foreach ($server in $serverlist)
{
#Get the scopes from each server
    Get-DHCPServerv4Scope -ComputerName $server.IPAddress | select ScopeID | 
#Get the lease information for each scope
    ForEach-Object {Get-DHCPServerv4Lease -ScopeId $_.ScopeId -ComputerName $Server.DNSName -AllLeases  | 
        where {$_.AddressState -like "*Reservation"} | Select-Object ScopeId,IPAddress,HostName,ClientID,AddressState }
}