【问题标题】:Retrieving DHCP Scopes检索 DHCP 范围
【发布时间】:2018-05-12 05:37:50
【问题描述】:

我的脚本在本地运行时有效,我试图从远程服务器获取所有 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:无法验证参数上的参数 '范围 ID'。参数为 null 或空。提供一个参数是 不为空或为空,然后重试该命令。在行:4 字符:36 + Get-DHCPServerv4Lease -ScopeID $.ScopeID -AllLeases |其中{$。 ... + ~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Get-DhcpServerv4Lease], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Get-DhcpServerv4Lease

【问题讨论】:

  • 您没有向$_ 输入任何内容,因此$_.ScopeID 将始终为空。做类似-ScopeID $B
  • 这至少给了我一个不同的错误,'ScopeID' 无法将值“TestDH01”转换为类型“System.Net.IPAddress”。错误:“指定的 IP 地址无效”
  • ScopeID 参数需要 IPv4 地址,并指定检索地址租约的范围。

标签: powershell scope dhcp


【解决方案1】:

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

#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 }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-17
    • 1970-01-01
    • 2017-02-15
    • 2011-01-18
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多