myITforum.com Community Forum myITforum.com Community Forum

Home  Forums  Blogs  Live Support chat  Search Articles  Wiki  FAQ  Email Lists  Register  Login  My Profile  Inbox  Address Book  My Subscription  My Forums 

Photo Gallery  Member List  Search  Calendars  FAQ  Ticket List  Log Out

All Forums RSS Feed Subscription:


  


Check for disabled computer accounts in AD

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
  Printable Version
All Forums >> [Scripting Technologies] >> VB Script >> Check for disabled computer accounts in AD Page: [1]
Login
Message << Older Topic   Newer Topic >>
Check for disabled computer accounts in AD - 6/19/2008 12:46:14 AM   
kwijibo

 

Posts: 3
Score: 0
Joined: 6/19/2008
Status: offline
Hi,

I've used this forum many times and find it a very useful resource, this is my first time posting though.

I have looked extensively for a solution for this but cannot find an answer. How can you check whether a computer account is disabled in AD or not using VBScript? I can find many solutions for doing this with user accounts but not for computer accounts?

Thanks in advance for any help.
Post #: 1
RE: Check for disabled computer accounts in AD - 6/19/2008 12:51:58 PM   
jsandys


Posts: 405
Score: 13
Joined: 3/24/2005
From: San Antonio, TX
Status: offline
No script needed.

dsquery computer -disabled lists all computers that are disabled.

dsquery computer -name computername -disabled lists computers that match the computername parameter if they are disabled.

dsquery user -disabled works for users.

< Message edited by jsandys -- 6/19/2008 12:55:53 PM >


_____________________________

Jason
________________________________________
http://myitforum.com/cs2/blogs/jsandys/default.aspx

(in reply to kwijibo)
Post #: 2
RE: Check for disabled computer accounts in AD - 6/19/2008 6:15:39 PM   
kwijibo

 

Posts: 3
Score: 0
Joined: 6/19/2008
Status: offline
Thanks for the reply,

I'm trying to do a check within a VBScript to see if a computer account is disabled before I do something else. Is there a way using VBScript I can perform the check?

(in reply to jsandys)
Post #: 3
RE: Check for disabled computer accounts in AD - 6/19/2008 10:44:24 PM   
jsandys


Posts: 405
Score: 13
Joined: 3/24/2005
From: San Antonio, TX
Status: offline
OK.  Here's a sample script from the Technet script repository: http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx?mfr=true.  This script gets info about a computer object, an IADsComputer object in ADSI term.s  If you look up IADsComputer in MSDN, there is unfortunately no reference to any property or method talking about the acocunt being disabled.  Fear not though.  If you look up the AD schema in MSDN (http://msdn.microsoft.com/en-us/library/ms680987(VS.85).aspx), you will see that the Computer is a subclass of the User class, thus everything that applies to a User object (IADsUser ADSI interface) also applies to the Computer object (IADsComputer interface).  If you do a web search on IADsComputer and AccountDisabled, you'll get the following link which also eludes to this but they are talking .Net code so it doesn;t exactly translate: http://www.ondotnet.com/pub/a/dotnet/2003/08/04/activedir.html

Thus we have the following:

Set objComputer = GetObject _
   ("LDAP://CN=atl-dc-01,CN=Computers,DC=fabrikam,DC=com")

objProperty = objComputer.Get("AccountDisabled")
Wscript.Echo "Account is Disabled: " & objProperty


_____________________________

Jason
________________________________________
http://myitforum.com/cs2/blogs/jsandys/default.aspx

(in reply to kwijibo)
Post #: 4
RE: Check for disabled computer accounts in AD - 6/20/2008 1:07:48 AM   
kwijibo

 

Posts: 3
Score: 0
Joined: 6/19/2008
Status: offline
Thanks very much that works great!

For anyone else here is what I knocked up:

'Checks if a computer account is disabled
Function isAccountDisabled(distName)

Set objComputer = GetObject(distName)

IF objComputer.AccountDisabled = True Then
result = True
Else
result = False
End If
isAccountDisabled = result

End Function

(in reply to jsandys)
Post #: 5
Page:   [1]
All Forums >> [Scripting Technologies] >> VB Script >> Check for disabled computer accounts in AD Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts



  
Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.234