Home » Microsoft Operations Manager 2005 » Script: Check Account Status

Contoso.se

Welcome to contoso.se! My name is Anders Bengtsson and this is my blog about Azure infrastructure and system management. I am a senior engineer in the FastTrack for Azure team, part of Azure Engineering, at Microsoft.  Contoso.se has two main purposes, first as a platform to share information with the community and the second as a notebook for myself.

Everything you read here is my own personal opinion and any code is provided "AS-IS" with no warranties.

Anders Bengtsson

MVP
MVP awarded 2007,2008,2009,2010

My Books
Service Manager Unleashed
Service Manager Unleashed
Orchestrator Unleashed
Orchestrator 2012 Unleashed
OMS
Inside the Microsoft Operations Management Suite

Script: Check Account Status

This is two simple script to check if a account is enable or disable. If enable, a local event will be created. In this example I check if the Guest account is enable, if it is a local event will be generated. You can then pickup that event with a event rule.

strUser = "LDAP://cn=Guest,cn=Users,dc=contoso,dc=internal"Set objUser = GetObject _
  (strUser)
 
If objUser.AccountDisabled = FALSE Then
 Const EVENT_WARNING = 2
 Set objShell = Wscript.CreateObject("Wscript.Shell")
 objShell.LogEvent EVENT_WARNING, _
        "The account " & strUser & " is no longer disable. Please investigate."
End If

If you want to check all accounts in a OU you can use the this script. It will check a OU named Service_accounts
set objOU = GetObject _
    ("LDAP://OU=Service_Accounts,DC=contoso,DC=internal")
 
ObjOU.Filter= Array("user")
For Each objUser in ObjOU
 
 strUser = "LDAP://" + objUser.distinguishedName
 Set objUser = GetObject _
   (strUser)
 
 If objUser.AccountDisabled = FALSE Then
 Const EVENT_WARNING = 2
 Set objShell = Wscript.CreateObject("Wscript.Shell")
 objShell.LogEvent EVENT_WARNING, _
        "The account " & strUser & " is no longer disable. Please investigate."
End If
Next


1 Comment

Comments are closed.