locked
trying to get server restart times - it picks up my local pc for every dc RRS feed

  • Question

  • What am I missing in my code, it picks up my local pc reboot time for every dc

    $dcs=(Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | select name
    foreach ($dc in $dcs)
    {Get-WmiObject win32_operatingsystem | select cname, @{LABEL='LastBootUpTime' ;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}}

    cname LastBootUpTime
    ----- --------------
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM
          4/11/2018 4:04:56 PM

    Thursday, April 12, 2018 5:51 PM

Answers

  • You will have to fix the WMI service on the server causing the error.  The firewall is the most common cause of this.


    \_(ツ)_/

    hm... 

    i bet on

    $dcs=(Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | select -expand dnshostname
    The error he gets means the name is unrecognized/not reachable/etc.

    gwmi win32_operatingsystem -ComputerName fake
    gwmi : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
    Get-WmiObject win32_operatingsystem -ComputerName $dc.name  should also help


    • Edited by Mekac Friday, April 13, 2018 5:57 PM
    • Marked as answer by Christopher Ellis Friday, April 13, 2018 5:58 PM
    Friday, April 13, 2018 5:50 PM

All replies

  • Try this:

    $dcs=(Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | select name
    foreach ($dc in $dcs)
    {
        Get-WmiObject win32_operatingsystem -ComputerName $dc | select CSName, @{LABEL='LastBootUpTime' ;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
    }


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Proposed as answer by jrv Thursday, April 12, 2018 6:34 PM
    Thursday, April 12, 2018 6:23 PM
  • when i run the new command i get RPC server is unavailable

    $dcs=(Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | select name
    foreach ($dc in $dcs)
     {
      Get-WmiObject win32_operatingsystem -ComputerName $dc | select CSName, @{LABEL='LastBootUpTime' ;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}}}


    Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
    At line:3 char:5
    +     Get-WmiObject win32_operatingsystem -ComputerName $dc | select CS ...
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
        + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

    Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
    At line:3 char:5
    +     Get-WmiObject win32_operatingsystem -ComputerName $dc | select CS ...
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Friday, April 13, 2018 3:29 PM
  • You will have to fix the WMI service on the server causing the error.  The firewall is the most common cause of this.


    \_(ツ)_/

    Friday, April 13, 2018 3:34 PM
  • You will have to fix the WMI service on the server causing the error.  The firewall is the most common cause of this.


    \_(ツ)_/

    hm... 

    i bet on

    $dcs=(Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ } | select -expand dnshostname
    The error he gets means the name is unrecognized/not reachable/etc.

    gwmi win32_operatingsystem -ComputerName fake
    gwmi : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
    Get-WmiObject win32_operatingsystem -ComputerName $dc.name  should also help


    • Edited by Mekac Friday, April 13, 2018 5:57 PM
    • Marked as answer by Christopher Ellis Friday, April 13, 2018 5:58 PM
    Friday, April 13, 2018 5:50 PM