Results 1 to 2 of 2

Thread: Ping machines part of a security Group

  1. #1
    pamarths is offline Beginner
    Join Date
    Nov 2009
    Location
    Hyderabad, India
    Posts
    14

    Default Ping machines part of a security Group

    Today I want to turn my some of the scripting efforts to public.

    Sometimes I get requirements to see how many machines are online which are part of a AD security group. I worst method I used to follow was dumping the group member list to some text file and making use of a batch script to ping the machine and check the status. This is pretty good but consuming some of my time for dumping and analyzing. So why below script is born….



    You just need to give the group DN in the script and execute it with cscript. That shows the machine status if it is online or not. Feel free to modify the script to match your requirements and let me know if I can be of any help.

    '################################################# #########################
    '# Purpose : To check the ping status of computers part of a security group
    '# Author : Sitaram Pamarthi
    '#
    '################################################# #########################
    'On Error Resume Next

    ' Replace with your group DN
    GroupDN="LDAP://CN=Your Group Name,OU=Your OU name,DC=domain,DC=com"

    Set objGroup = GetObject(GroupDN)
    objGroup.GetInfo
    arrMemberOf = objGroup.GetEx("member")
    For Each strMember in arrMemberOf
    Set objGroup1 = GetObject("LDAP://" & strMember)
    strHost=trim(objGroup1.dNSHostName)
    set objPing = GetObject("winmgmts:{impersonationLevel=impersonat e}").ExecQuery _
    ("select * from Win32_PingStatus where address = '" & strHost & "'")

    for each objRetStatus in objPing
    if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
    WScript.Echo strhost & " ==> host not reachable"
    else
    Ping = True
    wscript.echo strhost & " ==> Machine Reachable"
    end if
    next
    Next


    '#End of script.
    I am sure this can be made even more easily with PowerShell(with Quest AD pack). I will post that when I get some time.

    Happy Learning..,
    Sitaram Pamarthi
    Same is available at Sitaram's Blog: Script to ping machines part of Active Directory Security Group

  2. #2
    pamarths is offline Beginner
    Join Date
    Nov 2009
    Location
    Hyderabad, India
    Posts
    14

    Default Powershell code

    I made the powershell equivalent code for this.

    $groupmembers = Get-QADComputer -memberof "domain.com/ou-name/group-name"
    foreach ($member in $groupmembers) {
    $comp = $member.name
    $status = Get-WmiObject win32_Pingstatus -filter "Address = '$comp'"
    if($status.statuscode -eq 0) {
    write-host -foreground green "$comp(ONLINE)"
    }Else {
    write-host -foreground red "$comp(OFFLINE)"
    }
    }
    Happy Learning...,
    Sitaram Pamarthi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22