0

I'm simply trying to get all the Computers out of the AD and want to show me the IP, DNS Name, Mac-Address and description.

I got the WMI part working for my local computer but as soon as I try it with the AD Computer list its throwing around errors which i'm not able to solve myself.

I know that WMI reading is granted in our internal Network as we also use WMI Monitoring.

Powershell Code:

$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!"
    }
  }
Kevin
  • 193
  • 1
  • 4
  • 16
  • What are the error messages you are getting? – HAL9256 Mar 05 '19 at 16:49
  • [1] a pipe does NOT work at the start of a line - only in or at the _end_ of a line. [*grin*] ///// [2] take a look at the content of your `$C` variable. i suspect it is an AD object, not simple computer name. you likely need to use `$C.` where the prop name is whatever your `$C` object contains. – Lee_Dailey Mar 05 '19 at 16:52
  • @HAL9256 RCP-Server is not availabe HRESULT: 0x800706BA – Kevin Mar 05 '19 at 17:05
  • @Lee_Dailey [1] was a "graphical" thing as the line would be very long [2] i did this and it works now for some name's but still more errors then passes – Kevin Mar 05 '19 at 17:07
  • posting code that DOES NOT WORK is kinda silly when you are asking for help with your code. [*grin*] PoSh knows to continue after a pipe, so you can line wrap after that. ///// please show the code you are discussing ... right now i have no idea what your code actually is ... [*sigh ...*] – Lee_Dailey Mar 05 '19 at 17:09
  • "RCP-Server is not available" is the generic error for WMI can't connect. It could be the machine is off, RPC ports are blocked, etc. – HAL9256 Mar 05 '19 at 21:16

2 Answers2

1

I believe the issue is with the For loop. Passing the name $c is not passing in the name as the actual computer name, but as a custom PS Object. You can see this if you do a Write-Host:

$computerlist = Get-ADComputer -Filter * | select Name
foreach($c in $computerlist)
{
  Write-Host $c
}

@{Name=C1234}

You simply need to reference the Property e.g. $c.Name so your code looks like:

$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!"
  }
}
HAL9256
  • 12,384
  • 1
  • 34
  • 46
1

Try this and report back...

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

Update for the OP

As for …

Thx for the suggestion but i still get the same error message (HRESULT: 0x800706BA)

As stated by others, the RPC is not a PowerShell specific thing, it's a service / resource level thing.

See this Q&A

postanote
  • 15,138
  • 2
  • 14
  • 25
  • Thx for the suggestion but i still get the same error message (HRESULT: 0x800706BA) – Kevin Mar 06 '19 at 07:36
  • As far as i can see the most clients dont run the WMI service, as all our servers that are monitored are now fully running, but not the clients... therefor i need to script the start of the WMI service before or via GPO. – Kevin Mar 06 '19 at 07:45
  • i got the pc's running the wmi i have found out that those who are not responding are thin clients running a linux system – Kevin Mar 06 '19 at 08:07