Function to test if AD computers are online

This topic contains 4 replies, has 5 voices, and was last updated by  Adam Bertram 1 week, 4 days ago.

  • Author
    Posts
  • #85016

    Sam Gooch
    Participant

    I'm very new to Powershell, and I'm attempting to create a function which will test if AD computers are online using the Get-AD cmdlet. This function works, but I would like it to show the name of the AD computer beside its online/offline status. Any help with this would be greatly appreciated. Gist URL below.

    gist.github.com/anonymous/622d25f02ce071d2f9cd90c8927a7159

  • #85018

    postanote
    Participant

    Without looking at you gist location first. Know that there are several pre-built script for you to leverage to do this on this site forum, in the MS PowerShellGallery, TechNet, MSDN and the MS Scripting Guy's blog. Review and tweak as needed vs going from scratch, well, unless you are doing this for a learning experience. even with that, looking at how others do this is still educational.

    'gallery.technet.microsoft.com/scriptcenter/PowerShell-function-to-044d51a5'
    'blogs.technet.microsoft.com/heyscriptingguy/2011/11/19/query-ad-for-computers-and-use-ping-to-determine-status'
    'blogs.technet.microsoft.com/askds/2010/02/04/inventorying-computers-with-ad-powershell'

  • #85109

    Richard Siddaway
    Moderator

    Try this as a starting point

    Get-ADComputer -Filter * |
    foreach {
       
      $props = [ordered]@{
        ComputerName = $_.Name
        Online = (Test-Connection -ComputerName $_.Name -Count 1 -Quiet)
      }
    
      New-Object -TypeName PsObject -Property $props
    }
    

    It'll give output like this

    ComputerName Online
    ------------ ------
    W16DC01        True
    W16AS01        True
    W16DSC01       True
    W10PRV01      False
    W16RMT01       True
    W1709CN01      True
    W16CN01        True
    W17035CN01     True
    
  • #85147

    Anders
    Participant

    Hello Richard,

    Sorry, to hijack the thread.
    I know that [String] or any other data type declares the variable.
    But, what does [Ordered] do?, my guess would be that it ordered somehow?

    Maybe you have a link where i can find more info.

    Thanks in Advance

    /Anders

  • #85198

    Adam Bertram
    Moderator

    Moving to correct forum.

You must be logged in to reply to this topic.