【发布时间】: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