我只是想把所有的计算机都从AD中取出来,并想向我展示IP,DNS名称,Mac地址和描述。
我让WMI部分为我的本地计算机工作,但是当我尝试使用AD计算机列表时,它会抛出我自己无法解决的错误。
我知道WMI读取在我们的内部网络中被授予,因为我们也使用WMI监控。
Powershell代码:
$computerlist = Get-ADComputer -Filter * | select Name
foreach($c in $computerlist)
{
try
{
gwmi -class "Win32_NetworkAdapterConfiguration" -ComputerName $c |
select DNSHostName, MACAddress, IPAddress, Description |
where IPAddress -NotLike "" |
where Description -NotLike "VMware*"
}
catch
{
Write-Warning "$c is unreachable!"
}
}
试试这个并报告回来......
# Use a basic WMI connection check before checking the Network Adapter details
(Get-ADComputer -Filter *).Name |
foreach {
If((gwmi -ComputerName $PSItem -Class win32_process))
{
try
{
gwmi -class 'Win32_NetworkAdapterConfiguration' -ComputerName $PSItem |
select DNSHostName, MACAddress, IPAddress, Description |
where IPAddress -NotLike "" |
where Description -NotLike '*VMware*'
}
catch
{
Write-Warning "When processing $PSItem, some other error occurred!"
}
}
Else
{
Write-Warning -Message "WMI connection failed for host $PSItem, thus not reachable"
}
}
OP的更新
至于......
Thx的建议,但我仍然得到相同的错误消息(HRESULT:0x800706BA)
正如其他人所说,RPC不是PowerShell特有的东西,它是服务/资源级别的东西。
我相信问题在于For
循环。传递名称$c
不会将名称作为实际计算机名称传递,而是作为自定义PS对象传递。如果你做一个Write-Host
,你可以看到这个:
$computerlist = Get-ADComputer -Filter * | select Name
foreach($c in $computerlist)
{
Write-Host $c
}
@{Name=C1234}
您只需要引用该属性,例如$c.Name
所以你的代码看起来像:
$computerlist = Get-ADComputer -Filter * | select Name
foreach($c in $computerlist)
{
try
{
gwmi -class "Win32_NetworkAdapterConfiguration" -ComputerName $c.Name `
|select DNSHostName, MACAddress, IPAddress, Description `
|where IPAddress -NotLike "" `
|where Description -NotLike "VMware*" `
}
catch
{
Write-Warning "$c is unreachable!"
}
}