【发布时间】:2019-10-31 08:43:22
【问题描述】:
我需要获取不是 AD 域成员但从 DHCP 获得租约的客户端/计算机的列表。
我使用的代码看起来适用于其他用户,但我的输出文件中没有任何主机名。
Get-DhcpServerv4Lease -allleases -ScopeId 191.168.1.1 | Select-Object @{expression= {$_.hostname}; label='name' } | export-CSV -notypeinformation C:\dhcp\LeaseLog.csv
$leaselogpath = "c:\DHCP\LeaseLog.csv"
Import-csv -path $leaselogpath | foreach-object {
$ComputerName = $_.name.Replace(".domain.com",$null)
$Result = Get-ADComputer $ComputerName
If ($Result -eq $null) {
$RogueSystem = $_.Name
}
$RogueSystem | Out-File C:\DHCP\RogueClients.txt -Append $RogueSystem = $null
}
执行时,我收到有关域中缺少计算机的错误消息 - 正是我需要在输出文件中列出的计算机,但输出文件仍然为空。
Get-ADComputer:找不到标识为“TEST-PC1”的对象....
【问题讨论】:
-
您发布的代码由于换行符不正确(或更具体地说,缺少)而损坏。请edit您的问题并复制/粘贴您在脚本中的代码。当您发布的代码引入了您尝试调试的代码中不存在的其他问题时,我们无法为您提供帮助。
标签: powershell dhcp