Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - ping computer and remove from AD

Reply
 
Old 01-09-2009   #1 (permalink)
freddy


 
 

ping computer and remove from AD

New to VBscript. I would like to ping a computer that is listed in AD and
depending from the result I get back it should 1. leave it alone or 2. remove
it from AD

I got this script from microsoft:

On Error Resume Next
strComputer = "stmts00701"
strPingStatus = PingStatus(strComputer)
If strPingStatus = "Success" Then
Wscript.Echo "Success pinging " & strComputer
Else
Wscript.Echo "Failure pinging " & strComputer & ": " & strPingStatus
End If

'******************************************************************************

Function PingStatus(strComputer)

On Error Resume Next
strWorkstation = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strWorkstation &
"\root\cimv2")
Set colPings = objWMIService.ExecQuery _
("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'")
For Each objPing in colPings
Select Case objPing.StatusCode
Case 0 PingStatus = "Success"
Case 11001 PingStatus = "Status code 11001 - Buffer Too Small"
Case 11002 PingStatus = "Status code 11002 - Destination Net
Unreachable"
Case 11003 PingStatus = "Status code 11003 - Destination Host
Unreachable"
Case 11004 PingStatus = _
"Status code 11004 - Destination Protocol Unreachable"
Case 11005 PingStatus = "Status code 11005 - Destination Port
Unreachable"
Case 11006 PingStatus = "Status code 11006 - No Resources"
Case 11007 PingStatus = "Status code 11007 - Bad Option"
Case 11008 PingStatus = "Status code 11008 - Hardware Error"
Case 11009 PingStatus = "Status code 11009 - Packet Too Big"
Case 11010 PingStatus = "Status code 11010 - Request Timed Out"
Case 11011 PingStatus = "Status code 11011 - Bad Request"
Case 11012 PingStatus = "Status code 11012 - Bad Route"
Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired
Transit"
Case 11014 PingStatus = _
"Status code 11014 - TimeToLive Expired Reassembly"
Case 11015 PingStatus = "Status code 11015 - Parameter Problem"
Case 11016 PingStatus = "Status code 11016 - Source Quench"
Case 11017 PingStatus = "Status code 11017 - Option Too Big"
Case 11018 PingStatus = "Status code 11018 - Bad Destination"
Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC"
Case 11050 PingStatus = "Status code 11050 - General Failure"
Case Else PingStatus = "Status code " & objPing.StatusCode & _
" - Unable to determine cause of failure."
End Select
Next

End Function

if the status code is Case 11003 PingStatus = "Status code 11003 -
Destination Host Unreachable" than delete from AD
Else leave it alone
Wscript.echo "Request Timed Out"


My System SpecsSystem Spec
Old 01-09-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: ping computer and remove from AD


"freddy" <freddy@xxxxxx> wrote in message
news:21A5A230-77F1-461C-BF50-C6EF6FE18F4A@xxxxxx
Quote:

> New to VBscript. I would like to ping a computer that is listed in AD and
> depending from the result I get back it should 1. leave it alone or 2.
> remove
> it from AD
>
> I got this script from microsoft:
>
> On Error Resume Next
> strComputer = "stmts00701"
> strPingStatus = PingStatus(strComputer)
> If strPingStatus = "Success" Then
> Wscript.Echo "Success pinging " & strComputer
> Else
> Wscript.Echo "Failure pinging " & strComputer & ": " & strPingStatus
> End If
>
> '******************************************************************************
>
> Function PingStatus(strComputer)
>
> On Error Resume Next
> strWorkstation = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strWorkstation &
> "\root\cimv2")
> Set colPings = objWMIService.ExecQuery _
> ("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer &
> "'")
> For Each objPing in colPings
> Select Case objPing.StatusCode
> Case 0 PingStatus = "Success"
> Case 11001 PingStatus = "Status code 11001 - Buffer Too Small"
> Case 11002 PingStatus = "Status code 11002 - Destination Net
> Unreachable"
> Case 11003 PingStatus = "Status code 11003 - Destination Host
> Unreachable"
> Case 11004 PingStatus = _
> "Status code 11004 - Destination Protocol Unreachable"
> Case 11005 PingStatus = "Status code 11005 - Destination Port
> Unreachable"
> Case 11006 PingStatus = "Status code 11006 - No Resources"
> Case 11007 PingStatus = "Status code 11007 - Bad Option"
> Case 11008 PingStatus = "Status code 11008 - Hardware Error"
> Case 11009 PingStatus = "Status code 11009 - Packet Too Big"
> Case 11010 PingStatus = "Status code 11010 - Request Timed Out"
> Case 11011 PingStatus = "Status code 11011 - Bad Request"
> Case 11012 PingStatus = "Status code 11012 - Bad Route"
> Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired
> Transit"
> Case 11014 PingStatus = _
> "Status code 11014 - TimeToLive Expired Reassembly"
> Case 11015 PingStatus = "Status code 11015 - Parameter Problem"
> Case 11016 PingStatus = "Status code 11016 - Source Quench"
> Case 11017 PingStatus = "Status code 11017 - Option Too Big"
> Case 11018 PingStatus = "Status code 11018 - Bad Destination"
> Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC"
> Case 11050 PingStatus = "Status code 11050 - General Failure"
> Case Else PingStatus = "Status code " & objPing.StatusCode & _
> " - Unable to determine cause of failure."
> End Select
> Next
>
> End Function
>
> if the status code is Case 11003 PingStatus = "Status code 11003 -
> Destination Host Unreachable" than delete from AD
> Else leave it alone
> Wscript.echo "Request Timed Out"
>
A computer could be temporarily unreachable for several reasons. A better
plan would be to check the password last changed date or the last logon date
and decide if the computer account is "stale" based on that. Joe Richard's
free oldcmp utility is great for this and is recommended:

http://www.joeware.net/freetools/tools/oldcmp/index.htm

Most people when they decide a computer account is stale disable it and
perhaps move it to another container (OU). Only if there are no complaints
after a few weeks do they delete the objects. In any case, this link shows
how to delete a computer in VBScript:

http://www.microsoft.com/technet/scr.../cptrvb03.mspx

In your script, where you use the NetBIOS name of the computer, you would
need to use the NameTranslate object to convert this to the
distinguishedName so you could bind to the object and invoke the
DeleteObject method. See this link for details:

http://www.rlmueller.net/NameTranslateFAQ.htm

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 01-10-2009   #3 (permalink)
BigDaddyJim


 
 

Re: ping computer and remove from AD

On Jan 9, 4:51*pm, "Richard Mueller [MVP]" <rlmueller-
nos...@xxxxxx> wrote:
Quote:

> "freddy" <fre...@xxxxxx> wrote in message
>
> news:21A5A230-77F1-461C-BF50-C6EF6FE18F4A@xxxxxx
>
>
>
>
>
Quote:

> > New to VBscript. I would like to ping a computer that is listed in AD and
> > depending from the result I get back it should 1. leave it alone or 2.
> > remove
> > it from AD
>
Quote:

> > I got this script from microsoft:
>
Quote:

> > On Error Resume Next
> > strComputer = "stmts00701"
> > strPingStatus = PingStatus(strComputer)
> > If strPingStatus = "Success" Then
> > * *Wscript.Echo "Success pinging " & strComputer
> > Else
> > * *Wscript.Echo "Failure pinging " & strComputer & ": " & strPingStatus
> > End If
>
Quote:

> > '*******************************************************************************
>
Quote:

> > Function PingStatus(strComputer)
>
Quote:

> > * *On Error Resume Next
> > * *strWorkstation = "."
> > * *Set objWMIService = GetObject("winmgmts:" _
> > * * *& "{impersonationLevel=impersonate}!\\" & strWorkstation &
> > "\root\cimv2")
> > * *Set colPings = objWMIService.ExecQuery _
> > * * *("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer &
> > "'")
> > * *For Each objPing in colPings
> > * * * *Select Case objPing.StatusCode
> > * * * * * *Case 0 PingStatus = "Success"
> > * * * * * *Case 11001 PingStatus = "Status code 11001 - Buffer Too Small"
> > * * * * * *Case 11002 PingStatus = "Status code 11002 - Destination Net
> > Unreachable"
> > * * * * * *Case 11003 PingStatus = "Status code 11003 - Destination Host
> > Unreachable"
> > * * * * * *Case 11004 PingStatus = _
> > * * * * * * *"Status code 11004 - Destination Protocol Unreachable"
> > * * * * * *Case 11005 PingStatus = "Status code 11005 - Destination Port
> > Unreachable"
> > * * * * * *Case 11006 PingStatus = "Status code 11006 - No Resources"
> > * * * * * *Case 11007 PingStatus = "Status code 11007 - Bad Option"
> > * * * * * *Case 11008 PingStatus = "Status code 11008 - Hardware Error"
> > * * * * * *Case 11009 PingStatus = "Status code 11009 - Packet Too Big"
> > * * * * * *Case 11010 PingStatus = "Status code 11010 - Request Timed Out"
> > * * * * * *Case 11011 PingStatus = "Status code 11011 - Bad Request"
> > * * * * * *Case 11012 PingStatus = "Status code 11012 - Bad Route"
> > * * * * * *Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired
> > Transit"
> > * * * * * *Case 11014 PingStatus = _
> > * * * * * * *"Status code 11014 - TimeToLive Expired Reassembly"
> > * * * * * *Case 11015 PingStatus = "Status code 11015 - Parameter Problem"
> > * * * * * *Case 11016 PingStatus = "Status code 11016 - Source Quench"
> > * * * * * *Case 11017 PingStatus = "Status code 11017 - Option Too Big"
> > * * * * * *Case 11018 PingStatus = "Status code 11018 - Bad Destination"
> > * * * * * *Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC"
> > * * * * * *Case 11050 PingStatus = "Status code 11050 - General Failure"
> > * * * * * *Case Else PingStatus = "Status code " & objPing.StatusCode & _
> > * * * * * * * " - Unable to determine cause of failure."
> > * * * *End Select
> > * *Next
>
Quote:

> > End Function
>
Quote:

> > if the status code is Case 11003 PingStatus = "Status code 11003 -
> > Destination Host Unreachable" than delete from AD
> > Else leave it alone
> > Wscript.echo "Request Timed Out"
>
> A computer could be temporarily unreachable for several reasons. A better
> plan would be to check the password last changed date or the last logon date
> and decide if the computer account is "stale" based on that. Joe Richard's
> free oldcmp utility is great for this and is recommended:
>
> http://www.joeware.net/freetools/tools/oldcmp/index.htm
>
> Most people when they decide a computer account is stale disable it and
> perhaps move it to another container (OU). Only if there are no complaints
> after a few weeks do they delete the objects. In any case, this link shows
> how to delete a computer in VBScript:
>
> http://www.microsoft.com/technet/scr...d/computer/cpt...
>
> In your script, where you use the NetBIOS name of the computer, you would
> need to use the NameTranslate object to convert this to the
> distinguishedName so you could bind to the object and invoke the
> DeleteObject method. See this link for details:
>
> http://www.rlmueller.net/NameTranslateFAQ.htm
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab -http://www.rlmueller.net
> --- Hide quoted text -
>
> - Show quoted text -
I agree. If you get into the habit of unilaterally nuking computer
objects, it will come back to bite you when the user comes in and
turns the PC back on and can't log in. Seen it. Not pretty.

Disablng accounts is the way to go and then nuking them after a period
of time.

Jim
My System SpecsSystem Spec
Old 01-16-2009   #4 (permalink)
Al Dunbar


 
 

Re: ping computer and remove from AD


"BigDaddyJim" <hungerfordj@xxxxxx> wrote in message
news:4927856d-c1bd-4923-90c8-bb53df1dd131@xxxxxx
On Jan 9, 4:51 pm, "Richard Mueller [MVP]" <rlmueller-
nos...@xxxxxx> wrote:
Quote:

> "freddy" <fre...@xxxxxx> wrote in message
>
> news:21A5A230-77F1-461C-BF50-C6EF6FE18F4A@xxxxxx
>
>
>
>
>
Quote:

> > New to VBscript. I would like to ping a computer that is listed in AD
> > and
> > depending from the result I get back it should 1. leave it alone or 2.
> > remove
> > it from AD
>
Quote:

> > I got this script from microsoft:
>
Quote:

> > On Error Resume Next
> > strComputer = "stmts00701"
> > strPingStatus = PingStatus(strComputer)
> > If strPingStatus = "Success" Then
> > Wscript.Echo "Success pinging " & strComputer
> > Else
> > Wscript.Echo "Failure pinging " & strComputer & ": " & strPingStatus
> > End If
>
Quote:

> > '*******************************************************************************
>
Quote:

> > Function PingStatus(strComputer)
>
Quote:

> > On Error Resume Next
> > strWorkstation = "."
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\" & strWorkstation &
> > "\root\cimv2")
> > Set colPings = objWMIService.ExecQuery _
> > ("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer &
> > "'")
> > For Each objPing in colPings
> > Select Case objPing.StatusCode
> > Case 0 PingStatus = "Success"
> > Case 11001 PingStatus = "Status code 11001 - Buffer Too Small"
> > Case 11002 PingStatus = "Status code 11002 - Destination Net
> > Unreachable"
> > Case 11003 PingStatus = "Status code 11003 - Destination Host
> > Unreachable"
> > Case 11004 PingStatus = _
> > "Status code 11004 - Destination Protocol Unreachable"
> > Case 11005 PingStatus = "Status code 11005 - Destination Port
> > Unreachable"
> > Case 11006 PingStatus = "Status code 11006 - No Resources"
> > Case 11007 PingStatus = "Status code 11007 - Bad Option"
> > Case 11008 PingStatus = "Status code 11008 - Hardware Error"
> > Case 11009 PingStatus = "Status code 11009 - Packet Too Big"
> > Case 11010 PingStatus = "Status code 11010 - Request Timed Out"
> > Case 11011 PingStatus = "Status code 11011 - Bad Request"
> > Case 11012 PingStatus = "Status code 11012 - Bad Route"
> > Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired
> > Transit"
> > Case 11014 PingStatus = _
> > "Status code 11014 - TimeToLive Expired Reassembly"
> > Case 11015 PingStatus = "Status code 11015 - Parameter Problem"
> > Case 11016 PingStatus = "Status code 11016 - Source Quench"
> > Case 11017 PingStatus = "Status code 11017 - Option Too Big"
> > Case 11018 PingStatus = "Status code 11018 - Bad Destination"
> > Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC"
> > Case 11050 PingStatus = "Status code 11050 - General Failure"
> > Case Else PingStatus = "Status code " & objPing.StatusCode & _
> > " - Unable to determine cause of failure."
> > End Select
> > Next
>
Quote:

> > End Function
>
Quote:

> > if the status code is Case 11003 PingStatus = "Status code 11003 -
> > Destination Host Unreachable" than delete from AD
> > Else leave it alone
> > Wscript.echo "Request Timed Out"
>
> A computer could be temporarily unreachable for several reasons. A better
> plan would be to check the password last changed date or the last logon
> date
> and decide if the computer account is "stale" based on that. Joe Richard's
> free oldcmp utility is great for this and is recommended:
>
> http://www.joeware.net/freetools/tools/oldcmp/index.htm
>
> Most people when they decide a computer account is stale disable it and
> perhaps move it to another container (OU). Only if there are no complaints
> after a few weeks do they delete the objects. In any case, this link shows
> how to delete a computer in VBScript:
>
> http://www.microsoft.com/technet/scr...d/computer/cpt...
>
> In your script, where you use the NetBIOS name of the computer, you would
> need to use the NameTranslate object to convert this to the
> distinguishedName so you could bind to the object and invoke the
> DeleteObject method. See this link for details:
>
> http://www.rlmueller.net/NameTranslateFAQ.htm
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab -http://www.rlmueller.net
> --- Hide quoted text -
>
> - Show quoted text -
I agree. If you get into the habit of unilaterally nuking computer
objects, it will come back to bite you when the user comes in and
turns the PC back on and can't log in. Seen it. Not pretty.

Disablng accounts is the way to go and then nuking them after a period
of time.

=====

What do you mean "comes in and turns the PC back on and can't log in". What
about the case where a person reboots his computer at the precise time that
the script was run and the computer account is deleted before the PC comes
back up?

/Al


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Ping on Workgroup Computer Names Bad / IP Addresses Good / Internet Good Network & Sharing
cannot ping xp computer from vista Vista networking & sharing
Computer are online but can't ping each other Network & Sharing
I can acess the net + Fileshare but can not PING computer IPS? Network & Sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46