我只是想让所有计算机脱离广告,并想向我显示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!"
}
}
答案 0 :(得分:1)
我认为问题出在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!"
}
}
答案 1 :(得分:1)
尝试一下并向后报告...
# 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
至于……
建议,但我仍然收到相同的错误消息 (HRESULT:0x800706BA)
正如其他人所说,RPC不是特定于PowerShell的东西,而是服务/资源级别的东西。