Author Posts

November 27, 2017 at 7:19 pm

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

November 27, 2017 at 7:28 pm

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'

November 28, 2017 at 8:23 pm

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

November 29, 2017 at 1:27 pm

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

November 29, 2017 at 8:28 pm

Moving to correct forum.